10分钟让微信公众号成为智能客服_大模型服务平台百炼(Model Studio)-阿里云帮助中心
步骤很详细,一步一步的走就行,难的是个人服务器部署,响应token
这里我用的是flask框架,代码如下
from flask import Flask, request
import hashlibapp = Flask(__name__)# Token used for verification
TOKEN = "cxh"def sha1_hash(data):"""Generates SHA1 hash of the given data."""return hashlib.sha1(data.encode('utf-8')).hexdigest()@app.route('/checkUrl', methods=['GET'])
def check_url():# Fetch parameters from the requestnonce = request.args.get('nonce')timestamp = request.args.get('timestamp')signature = request.args.get('signature')echostr = request.args.get('echostr')# Create a list of parametersparam_list = [nonce, timestamp, TOKEN]# Sort the parametersparam_list.sort()# Concatenate the sorted parametersconcat_str = ''.join(param_list)# Generate SHA1 hashencode = sha1_hash(concat_str)print(f"WeChat message received: {echostr}")print(echostr)return echostr# Compare the generated hash with the signature# if encode == signature:# return echostr# else:# return ''if __name__ == '__main__':app.run(debug=True,port=80,host='0.0.0.0')
