|  | @@ -10,24 +10,26 @@ CORS(app, resources=r'/*')
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  # 操作文件,读取本地
 |  |  # 操作文件,读取本地
 | 
											
												
													
														|  | -def set_local_file_json(val):
 |  | 
 | 
											
												
													
														|  | -    send_status_value = {"status":val}
 |  | 
 | 
											
												
													
														|  | -    with open("1.json","w",encoding="utf-8") as f:
 |  | 
 | 
											
												
													
														|  | -        f.write(json.dumps(send_status_value))
 |  | 
 | 
											
												
													
														|  | 
 |  | +def set_local_file_json(obj):
 | 
											
												
													
														|  | 
 |  | +    with open("local.json","w",encoding="utf-8") as f:
 | 
											
												
													
														|  | 
 |  | +        f.write(json.dumps(obj,ensure_ascii=False))
 | 
											
												
													
														|  |          f.close()
 |  |          f.close()
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  def get_local_file_json():
 |  |  def get_local_file_json():
 | 
											
												
													
														|  |      try:
 |  |      try:
 | 
											
												
													
														|  | -        with open("1.json","r",encoding="utf-8") as f:
 |  | 
 | 
											
												
													
														|  | 
 |  | +        with open("local.json","r",encoding="utf-8") as f:
 | 
											
												
													
														|  |              return json.loads(f.read())
 |  |              return json.loads(f.read())
 | 
											
												
													
														|  |      except:
 |  |      except:
 | 
											
												
													
														|  | -        set_local_file_json("0")
 |  | 
 | 
											
												
													
														|  | -        return {"status":0}
 |  | 
 | 
											
												
													
														|  | 
 |  | +        return {"status":0,"project":[]}
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  # current_path
 |  |  # current_path
 | 
											
												
													
														|  |  current_path = os.getcwd()
 |  |  current_path = os.getcwd()
 | 
											
												
													
														|  |  res_json = {"code":0,"msg":"成功"}
 |  |  res_json = {"code":0,"msg":"成功"}
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | 
 |  | +global_params ={
 | 
											
												
													
														|  | 
 |  | +    "token":"",
 | 
											
												
													
														|  | 
 |  | +}
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  # 1.小程序打包
 |  |  # 1.小程序打包
 | 
											
												
													
														|  |  def build_mini_program(branch):
 |  |  def build_mini_program(branch):
 | 
											
										
											
												
													
														|  | @@ -90,7 +92,8 @@ def edit_mode_by_file(project,mode):
 | 
											
												
													
														|  |      res_json["msg"] = "文件修改成功"
 |  |      res_json["msg"] = "文件修改成功"
 | 
											
												
													
														|  |      
 |  |      
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -def upload_img_by_feishu(token):
 |  | 
 | 
											
												
													
														|  | 
 |  | +def upload_img_by_feishu():
 | 
											
												
													
														|  | 
 |  | +    token = global_params["token"]
 | 
											
												
													
														|  |      key = ""
 |  |      key = ""
 | 
											
												
													
														|  |      url = "https://open.feishu.cn/open-apis/im/v1/images"
 |  |      url = "https://open.feishu.cn/open-apis/im/v1/images"
 | 
											
												
													
														|  |      files = {
 |  |      files = {
 | 
											
										
											
												
													
														|  | @@ -102,16 +105,14 @@ def upload_img_by_feishu(token):
 | 
											
												
													
														|  |      }
 |  |      }
 | 
											
												
													
														|  |      res = requests.post(url,headers=headers,files=files).json()
 |  |      res = requests.post(url,headers=headers,files=files).json()
 | 
											
												
													
														|  |      if res["code"] == 0:
 |  |      if res["code"] == 0:
 | 
											
												
													
														|  | -        key = res["data"]["image_key"]
 |  | 
 | 
											
												
													
														|  | 
 |  | +        global_params["img_key"] = res["data"]["image_key"]
 | 
											
												
													
														|  |          res_json["code"] = 0
 |  |          res_json["code"] = 0
 | 
											
												
													
														|  |      else:
 |  |      else:
 | 
											
												
													
														|  |          res_json["code"] = 4
 |  |          res_json["code"] = 4
 | 
											
												
													
														|  |          res_json["msg"] = "飞书上传图片失败"
 |  |          res_json["msg"] = "飞书上传图片失败"
 | 
											
												
													
														|  |          
 |  |          
 | 
											
												
													
														|  | -    return key
 |  | 
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  def tenant_access_token_by_feishu():
 |  |  def tenant_access_token_by_feishu():
 | 
											
												
													
														|  | -    token = ""
 |  | 
 | 
											
												
													
														|  |      url = "https://open.feishu.cn/open-apis/auth/v3/tenant_access_token/internal"
 |  |      url = "https://open.feishu.cn/open-apis/auth/v3/tenant_access_token/internal"
 | 
											
												
													
														|  |      params = {
 |  |      params = {
 | 
											
												
													
														|  |          "app_id":"cli_a1ec07458838d00c",
 |  |          "app_id":"cli_a1ec07458838d00c",
 | 
											
										
											
												
													
														|  | @@ -119,17 +120,16 @@ def tenant_access_token_by_feishu():
 | 
											
												
													
														|  |      }
 |  |      }
 | 
											
												
													
														|  |      res = requests.post(url,data=params).json()
 |  |      res = requests.post(url,data=params).json()
 | 
											
												
													
														|  |      if res["code"] == 0:
 |  |      if res["code"] == 0:
 | 
											
												
													
														|  | -        token = res["tenant_access_token"]
 |  | 
 | 
											
												
													
														|  | 
 |  | +        global_params["token"] = res["tenant_access_token"]
 | 
											
												
													
														|  |          res_json["msg"] = "获取飞书签名成功"
 |  |          res_json["msg"] = "获取飞书签名成功"
 | 
											
												
													
														|  |          res_json["code"] = 0
 |  |          res_json["code"] = 0
 | 
											
												
													
														|  |      else:
 |  |      else:
 | 
											
												
													
														|  |          res_json["code"] = 4
 |  |          res_json["code"] = 4
 | 
											
												
													
														|  |          res_json["msg"] = "获取飞书签名失败"
 |  |          res_json["msg"] = "获取飞书签名失败"
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -    return token
 |  | 
 | 
											
												
													
														|  | -
 |  | 
 | 
											
												
													
														|  | -def send_msg_by_feishu(token,img_key,chat_id,project_name,mode_name):
 |  | 
 | 
											
												
													
														|  | -    token = tenant_access_token_by_feishu()
 |  | 
 | 
											
												
													
														|  | 
 |  | +def send_msg_by_feishu(chat_id,project_name,mode_name):
 | 
											
												
													
														|  | 
 |  | +    token = global_params["token"]
 | 
											
												
													
														|  | 
 |  | +    img_key = global_params["img_key"]
 | 
											
												
													
														|  |      url ="https://open.feishu.cn/open-apis/im/v1/messages?receive_id_type=chat_id"
 |  |      url ="https://open.feishu.cn/open-apis/im/v1/messages?receive_id_type=chat_id"
 | 
											
												
													
														|  |      headers = {
 |  |      headers = {
 | 
											
												
													
														|  |          "Authorization":"Bearer "+token,
 |  |          "Authorization":"Bearer "+token,
 | 
											
										
											
												
													
														|  | @@ -163,7 +163,8 @@ def send_msg_by_feishu(token,img_key,chat_id,project_name,mode_name):
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  # 获取群
 |  |  # 获取群
 | 
											
												
													
														|  | -def get_group_by_feishu(token):
 |  | 
 | 
											
												
													
														|  | 
 |  | +def get_group_by_feishu():
 | 
											
												
													
														|  | 
 |  | +    token = global_params["token"]
 | 
											
												
													
														|  |      headers = {
 |  |      headers = {
 | 
											
												
													
														|  |          "Authorization":"Bearer "+token,
 |  |          "Authorization":"Bearer "+token,
 | 
											
												
													
														|  |          "Content-Type": "application/json;charset=UTF-8"
 |  |          "Content-Type": "application/json;charset=UTF-8"
 | 
											
										
											
												
													
														|  | @@ -183,11 +184,18 @@ def func():
 | 
											
												
													
														|  |      # return 'Welcome to auto-mini-program-build-preview server. only can run on MacOS.'
 |  |      # return 'Welcome to auto-mini-program-build-preview server. only can run on MacOS.'
 | 
											
												
													
														|  |      return redirect("static/dist/index.html")
 |  |      return redirect("static/dist/index.html")
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | 
 |  | +@app.route('/getProject')
 | 
											
												
													
														|  | 
 |  | +def getProject():
 | 
											
												
													
														|  | 
 |  | +    local_data = get_local_file_json()
 | 
											
												
													
														|  | 
 |  | +    res_json["code"] = 0
 | 
											
												
													
														|  | 
 |  | +    res_json["data"] = local_data["project"]
 | 
											
												
													
														|  | 
 |  | +    return res_json
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  |  @app.route('/getGroup')
 |  |  @app.route('/getGroup')
 | 
											
												
													
														|  |  def getGroup():
 |  |  def getGroup():
 | 
											
												
													
														|  | -    token = tenant_access_token_by_feishu()
 |  | 
 | 
											
												
													
														|  | 
 |  | +    tenant_access_token_by_feishu()
 | 
											
												
													
														|  |      res_json["code"] = 0
 |  |      res_json["code"] = 0
 | 
											
												
													
														|  | -    res_json["data"] = get_group_by_feishu(token)
 |  | 
 | 
											
												
													
														|  | 
 |  | +    res_json["data"] = get_group_by_feishu()
 | 
											
												
													
														|  |      return res_json
 |  |      return res_json
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  @app.route('/send',methods=['POST'])
 |  |  @app.route('/send',methods=['POST'])
 | 
											
										
											
												
													
														|  | @@ -198,9 +206,13 @@ def send():
 | 
											
												
													
														|  |              res_json["code"] = 9
 |  |              res_json["code"] = 9
 | 
											
												
													
														|  |              res_json["msg"] = "当前有人打包,请稍后尝试"
 |  |              res_json["msg"] = "当前有人打包,请稍后尝试"
 | 
											
												
													
														|  |              return res_json
 |  |              return res_json
 | 
											
												
													
														|  | -        set_local_file_json("1")
 |  | 
 | 
											
												
													
														|  | 
 |  | +        
 | 
											
												
													
														|  | 
 |  | +        local_data["status"] = '1'
 | 
											
												
													
														|  | 
 |  | +        set_local_file_json(local_data)
 | 
											
												
													
														|  |          res_json["code"] = 0
 |  |          res_json["code"] = 0
 | 
											
												
													
														|  |          res_json["msg"] = "成功"
 |  |          res_json["msg"] = "成功"
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +        # 接受参数
 | 
											
												
													
														|  |          chat_id = request.json["chat_id"]
 |  |          chat_id = request.json["chat_id"]
 | 
											
												
													
														|  |          branch = request.json["branch"]
 |  |          branch = request.json["branch"]
 | 
											
												
													
														|  |          page = request.json["page"]
 |  |          page = request.json["page"]
 | 
											
										
											
												
													
														|  | @@ -208,42 +220,38 @@ def send():
 | 
											
												
													
														|  |          mode = request.json["mode"]
 |  |          mode = request.json["mode"]
 | 
											
												
													
														|  |          project_name = request.json["project_name"]
 |  |          project_name = request.json["project_name"]
 | 
											
												
													
														|  |          mode_name = request.json["mode_name"]
 |  |          mode_name = request.json["mode_name"]
 | 
											
												
													
														|  | -        # ------- 微信打包 ------
 |  | 
 | 
											
												
													
														|  | -        # 1.小程序打包
 |  | 
 | 
											
												
													
														|  | -        build_mini_program(branch)
 |  | 
 | 
											
												
													
														|  | -        if res_json["code"] != 0:
 |  | 
 | 
											
												
													
														|  | -            set_local_file_json("0")
 |  | 
 | 
											
												
													
														|  | -            return res_json
 |  | 
 | 
											
												
													
														|  | -        # 2.修改环境
 |  | 
 | 
											
												
													
														|  | -        edit_mode_by_file(project,mode)
 |  | 
 | 
											
												
													
														|  | -        if res_json["code"] != 0:
 |  | 
 | 
											
												
													
														|  | -            set_local_file_json("0")
 |  | 
 | 
											
												
													
														|  | -            return res_json
 |  | 
 | 
											
												
													
														|  | -        # 3.微信编译图片
 |  | 
 | 
											
												
													
														|  | -        time.sleep(1)
 |  | 
 | 
											
												
													
														|  | -        create_preview(project,page)
 |  | 
 | 
											
												
													
														|  | -        
 |  | 
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -        # -------- 飞书 --------
 |  | 
 | 
											
												
													
														|  | -        # 1.获取签名
 |  | 
 | 
											
												
													
														|  | -        if res_json["code"] != 0:
 |  | 
 | 
											
												
													
														|  | -            set_local_file_json("0")
 |  | 
 | 
											
												
													
														|  | -            return res_json
 |  | 
 | 
											
												
													
														|  | -        token = tenant_access_token_by_feishu()
 |  | 
 | 
											
												
													
														|  | -        # # 2.获取imgKey
 |  | 
 | 
											
												
													
														|  | -        if res_json["code"] != 0:
 |  | 
 | 
											
												
													
														|  | -            set_local_file_json("0")
 |  | 
 | 
											
												
													
														|  | -            return res_json
 |  | 
 | 
											
												
													
														|  | -        img_key = upload_img_by_feishu(token)
 |  | 
 | 
											
												
													
														|  | -        # # 3.飞书发送消息
 |  | 
 | 
											
												
													
														|  | -        if res_json["code"] != 0:
 |  | 
 | 
											
												
													
														|  | -            set_local_file_json("0")
 |  | 
 | 
											
												
													
														|  | -            return res_json
 |  | 
 | 
											
												
													
														|  | -        send_msg_by_feishu(token,img_key,chat_id,project_name,mode_name)
 |  | 
 | 
											
												
													
														|  | 
 |  | +        func_arr = [
 | 
											
												
													
														|  | 
 |  | +            # ------- 微信打包 ------
 | 
											
												
													
														|  | 
 |  | +            # 1.小程序打包
 | 
											
												
													
														|  | 
 |  | +            build_mini_program(branch),
 | 
											
												
													
														|  | 
 |  | +            # 2.修改环境
 | 
											
												
													
														|  | 
 |  | +            edit_mode_by_file(project,mode),
 | 
											
												
													
														|  | 
 |  | +            time.sleep(1),
 | 
											
												
													
														|  | 
 |  | +            create_preview(project,page),
 | 
											
												
													
														|  | 
 |  | +            # -------- 飞书 --------
 | 
											
												
													
														|  | 
 |  | +            # 1.获取签名
 | 
											
												
													
														|  | 
 |  | +            tenant_access_token_by_feishu(),
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +            upload_img_by_feishu(),
 | 
											
												
													
														|  | 
 |  | +            send_msg_by_feishu(chat_id,project_name,mode_name)
 | 
											
												
													
														|  | 
 |  | +        ]
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +        # 循环方法判断
 | 
											
												
													
														|  | 
 |  | +        for item in func_arr:
 | 
											
												
													
														|  | 
 |  | +            item
 | 
											
												
													
														|  | 
 |  | +            if res_json["code"] != 0:
 | 
											
												
													
														|  | 
 |  | +                local_data["status"] = '0'
 | 
											
												
													
														|  | 
 |  | +                set_local_file_json(local_data)
 | 
											
												
													
														|  | 
 |  | +                return res_json
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +        # 正常执行完
 | 
											
												
													
														|  | 
 |  | +        local_data["status"] = '0'
 | 
											
												
													
														|  | 
 |  | +        set_local_file_json(local_data)
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -        set_local_file_json("0")
 |  | 
 | 
											
												
													
														|  |      except Exception as ex:
 |  |      except Exception as ex:
 | 
											
												
													
														|  | -        set_local_file_json("0")
 |  | 
 | 
											
												
													
														|  | 
 |  | +        local_data["status"] = '0'
 | 
											
												
													
														|  | 
 |  | +        set_local_file_json(local_data)
 | 
											
												
													
														|  |          res_json["code"] = 9
 |  |          res_json["code"] = 9
 | 
											
												
													
														|  |          print(ex)
 |  |          print(ex)
 | 
											
												
													
														|  |          res_json["msg"] = ex.args
 |  |          res_json["msg"] = ex.args
 | 
											
										
											
												
													
														|  | @@ -279,4 +287,4 @@ def get_branch():
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  if __name__ == '__main__':
 |  |  if __name__ == '__main__':
 | 
											
												
													
														|  | -    app.run(host='0.0.0.0', port=7777, debug=True)
 |  | 
 | 
											
												
													
														|  | 
 |  | +    app.run(host='0.0.0.0', port=7777, debug=True)
 |