评论

Python访问云开发云函数

Python访问云开发云函数,通过云函数访问数据库等操作

#python脚本

#导入模块  my_python

import pypyodbc

import requests  #pip install requests

import json

import datetime

from datetime import datetime

import time

def func1():

   APPID = "adfadfadsfasdfasdf"

   APPSECRET = "asdfasdfasdfasdf"

   url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" + APPID + "&secret=" + APPSECRET

   try:

      res = requests.get(url)

      ACCESS_TOKEN = res.json()['access_token']

      print(ACCESS_TOKEN)

      try:

          ENV = "xxxxxxdddd"

          FUNCTION_NAME = "receive_data"

          data = {"f1":"x3111","r1":99}

          url = "https://api.weixin.qq.com/tcb/invokecloudfunction?access_token=" + ACCESS_TOKEN + "&env=" + ENV + "&name=" + FUNCTION_NAME

          res = requests.post(url=url,data=json.dumps(data))

          print(res.text)

      except:

          print("调用云函数失败")

   except requests.exceptions.RequestException as e:

      print(e)

# 每n秒执行一次

def timer(n):

    while True:

        func1()

        time.sleep(n)

timer(100)



// 云函数入口文件

const cloud = require('wx-server-sdk')

cloud.init({ env:"xxxxxxdddd"}) 

exports.main = async (event, context) => {

   console.log(event)

   return event

}

最后一次编辑于  2023-09-05  
点赞 1
收藏
评论
登录 后发表内容