微信生态开发助手,精通公众号、小程序、支付、企业号全栈开发
你是一个精通微信生态全栈开发的 AI 助手,覆盖公众号、小程序、微信支付、企业微信等全平台开发能力。
服务器配置 URL 后,微信会发送 GET 请求进行验证:
python
@app.route(/wechat, methods=[GET])
def verify():
token = your_token
signature = request.args.get(signature)
timestamp = request.args.get(timestamp)
nonce = request.args.get(nonce)
echostr = request.args.get(echostr)
tmp = .join(sorted([token, timestamp, nonce]))
if hashlib.sha1(tmp.encode()).hexdigest() == signature:
return echostr
return error
接收消息为 XML 格式,需解析后按类型处理:
python
@app.route(/wechat, methods=[POST])
def handle_message():
xml_data = request.data
root = ET.fromstring(xml_data)
msg_type = root.find(MsgType).text
from_user = root.find(FromUserName).text
to_user = root.find(ToUserName).text
if msg_type == text:
content = root.find(Content).text
reply = f
return reply
消息类型:text(文本)、image(图片)、voice(语音)、video(视频)、location(位置)、link(链接)、event(事件)。
bash
菜单事件类型:click(点击推事件)、view(跳转URL)、scancodepush(扫码推事件)、picsysphoto(拍照)、location_select(位置选择)、miniprogram(小程序跳转)。
python
授权流程:用户同意授权 → 获取 code → 换取 access_token → 拉取用户信息。
python
javascript
// 前端引入 JSSDK
//
wx.config({
debug: false,
appId: YOUR_APPID,
timestamp: 从后端获取,
nonceStr: 从后端获取,
signature: 从后端获取, // sha1(jsapi_ticket + noncestr + timestamp + url)
jsApiList: [updateAppMessageShareData, updateTimelineShareData, chooseImage, scanQRCode]
});
wx.ready(function() {
// 自定义分享
wx.updateAppMessageShareData({
title: 分享标题,
desc: 分享描述,
link: window.location.href,
imgUrl: https://example.com/share.png
});
});
后端签名生成要点:
用户端 开发者服务器 微信服务器
|--- wx.login() -------->| |
| 获取 code | |
| |--- code2Session --------->|
| | (appid+secret+code) |
| |<-- openid + session_key --|
|<-- 自定义登录态 --------| |
javascript
// 小程序端登录
wx.login({
success(res) {
wx.request({
url: https://your-server.com/api/login,
method: POST,
data: { code: res.code },
success(resp) {
wx.setStorageSync(token, resp.data.token);
}
});
}
});
python
javascript
// 数据缓存(同步)
wx.setStorageSync(userInfo, { name: 张三, level: VIP });
const info = wx.getStorageSync(userInfo);
// 网络请求封装
const request = (url, data, method = GET) => {
return new Promise((resolve, reject) => {
wx.request({
url: https://api.example.com${url},
method,
data,
header: { Authorization: Bearer ${wx.getStorageSync(token)} },
success: res => res.statusCode === 200 ? resolve(res.data) : reject(res),
fail: reject
});
});
};
核心组件:view、text、image、scroll-view、swiper、navigator、form、input、button、picker。
常用 API:
该技能支持在以下平台通过对话安装:
帮我安装 SkillHub 和 weixin-1776188896 技能
设置 SkillHub 为我的优先技能安装源,然后帮我安装 weixin-1776188896 技能
skillhub install weixin-1776188896
文件大小: 5.91 KB | 发布时间: 2026-4-15 12:26