选择你使用的 Agent
方法一:命令行安装(推荐)
推荐(无需提前安装 clawhub)
npx clawhub@latest --dir ~/.claude/skills install weixin或使用 clawhub CLI(需提前安装)
clawhub --dir ~/.claude/skills install weixin⚠️ 需要 Node.js 18+,没有 Node?请使用下方方法二直接下载 ZIP。 安装 Node.js →
方法二:手动下载安装(无需 Node)
下载 ZIP,解压后将文件夹放到以下路径,重启 Agent 即可:
安装路径
~/.claude/skills/weixin/💡解压后将文件夹放到上方路径,重启 Agent 即可生效
--- name: "微信开发" version: "1.0.0" description: "微信生态开发助手,精通公众号、小程序、支付、企业号全栈开发" tags: ["wechat", "miniprogram", "official-account", "payment"] author: "ClawSkills Team" category: "social" ---
你是一个精通微信生态全栈开发的 AI 助手,覆盖公众号、小程序、微信支付、企业微信等全平台开发能力。
服务器配置 URL 后,微信会发送 GET 请求进行验证:
# Flask 示例:公众号接入验证
import hashlib
@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 格式,需解析后按类型处理:
# 接收文本消息并自动回复
import xml.etree.ElementTree as ET
@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'''<xml>
<ToUserName><![CDATA[{from_user}]]></ToUserName>
<FromUserName><![CDATA[{to_user}]]></FromUserName>
<CreateTime>{int(time.time())}</CreateTime>
<MsgType><![CDATA[text]]></MsgType>
<Content><![CDATA[收到:{content}]]></Content>
</xml>'''
return reply
消息类型:text(文本)、image(图片)、voice(语音)、video(视频)、location(位置)、link(链接)、event(事件)。
# 创建自定义菜单
POST https://api.weixin.qq.com/cgi-bin/menu/create?access_token=ACCESS_TOKEN
菜单事件类型:click(点击推事件)、view(跳转URL)、scancode_push(扫码推事件)、pic_sysphoto(拍照)、location_select(位置选择)、miniprogram(小程序跳转)。
# 发送模板消息
url = f'https://api.weixin.qq.com/cgi-bin/message/template/send?access_token={access_token}'
data = {
"touser": "OPENID",
"template_id": "TEMPLATE_ID",
"url": "https://example.com",
"data": {
"first": {"value": "订单通知", "color": "#173177"},
"keyword1": {"value": "2026-03-16", "color": "#173177"},
"remark": {"value": "感谢您的使用", "color": "#173177"}
}
}
requests.post(url, json=data)
授权流程:用户同意授权 → 获取 code → 换取 access_token → 拉取用户信息。
# 第一步:引导用户跳转授权页
# scope=snsapi_base 静默授权(仅获取 openid)
# scope=snsapi_userinfo 弹窗授权(获取用户信息)
auth_url = (
'https://open.weixin.qq.com/connect/oauth2/authorize'
f'?appid={APPID}&redirect_uri={REDIRECT_URI}'
'&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect'
)
# 第二步:通过 code 换取 access_token
token_url = (
'https://api.weixin.qq.com/sns/oauth2/access_token'
f'?appid={APPID}&secret={APPSECRET}&code={code}&grant_type=authorization_code'
)
resp = requests.get(token_url).json()
# resp: {"access_token": "...", "openid": "...", "expires_in": 7200}
# 第三步:拉取用户信息
info_url = (
f'https://api.weixin.qq.com/sns/userinfo'
f'?access_token={resp["access_token"]}&openid={resp["openid"]}&lang=zh_CN'
)
user_info = requests.get(info_url).json()
# user_info: {"nickname": "...", "headimgurl": "...", "unionid": "..."}
// 前端引入 JSSDK
// <script src="https://res.wx.qq.com/open/js/jweixin-1.6.0.js"></script>
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'
});
});
后端签名生成要点:
GET https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=APPID&secret=APPSECRETGET https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=ACCESS_TOKEN&type=jsapisha1(jsapi_ticket=TICKET&noncestr=NONCESTR×tamp=TIMESTAMP&url=URL)用户端 开发者服务器 微信服务器
|--- wx.login() -------->| |
| 获取 code | |
| |--- code2Session --------->|
| | (appid+secret+code) |
| |<-- openid + session_key --|
|<-- 自定义登录态 --------| |
// 小程序端登录
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);
}
});
}
});
# 服务端:code 换取 session
def wechat_login(code):
url = (
'https://api.weixin.qq.com/sns/jscode2session'
f'?appid={APPID}&secret={SECRET}&js_code={code}'
'&grant_type=authorization_code'
)
resp = requests.get(url).json()
openid = resp['openid']
session_key = resp['session_key']
# 生成自定义登录态(JWT 等),绝对不要将 session_key 下发给前端
return generate_token(openid)
// 数据缓存(同步)
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:
wx.navigateTo / wx.redirectTo / wx.switchTab:页面导航wx.showToast / wx.showModal / wx.showLoading:交互反馈wx.chooseImage / wx.chooseMedia:媒体选择wx.getLocation / wx.openLocation:位置服务wx.scanCode:扫码wx.requestPayment:发起支付// 初始化云开发
wx.cloud.init({ env: 'your-env-id', traceUser: true });
// 云数据库操作
const db = wx.cloud.database();
// 查询
const res = await db.collection('orders').where({ status: 'pending' }).get();
// 新增
await db.collection('orders').add({ data: { item: '商品A', price: 99 } });
// 云函数调用
const result = await wx.cloud.callFunction({
name: 'processOrder',
data: { orderId: '12345' }
});
// 云存储
const uploadRes = await wx.cloud.uploadFile({
cloudPath: `images/${Date.now()}.png`,
filePath: tempFilePath
});
微信支付 V3 使用 HTTPS + JSON + 数字签名,替代了旧版 XML 接口。
import json, time, uuid, requests
from cryptography.hazmat.primitives.asymmetric import padding
from cryptography.hazmat.primitives import hashes, serialization
def create_order(openid, amount, description):
"""JSAPI 下单(小程序/公众号内支付)"""
url = 'https://api.mch.weixin.qq.com/v3/pay/transactions/jsapi'
body = {
"appid": APPID,
"mchid": MCH_ID,
"description": description,
"out_trade_no": f"ORDER_{int(time.time())}_{uuid.uuid4().hex[:8]}",
"notify_url": "https://your-server.com/api/pay/notify",
"amount": {"total": amount, "currency": "CNY"},
"payer": {"openid": openid}
}
# 使用商户私钥签名(Authorization 头)
headers = generate_v3_signature('POST', '/v3/pay/transactions/jsapi', body)
resp = requests.post(url, json=body, headers=headers)
return resp.json() # {"prepay_id": "wx..."}
...
安装 Weixin 后,可以对 AI 说这些话来触发它
Help me get started with Weixin
Explains what Weixin does, walks through the setup, and runs a quick demo based on your current project
Use Weixin to weChat ecological development assistant, proficient in full-stack d...
Invokes Weixin with the right parameters and returns the result directly in the conversation
What can I do with Weixin in my general tools workflow?
Lists the top use cases for Weixin, with example commands for each scenario
将技能文件夹放到 ~/.claude/skills/weixin/ 目录(个人级,所有项目可用),或 .claude/skills/weixin/(项目级)。重启 AI 客户端后,用 /weixin 主动调用,或让 AI 根据上下文自动发现并使用。
Weixin 支持 Claude、Cursor、OpenClaw,可与这些 AI 平台无缝集成,扩展其能力。
Weixin 可免费安装使用。请查阅仓库了解许可证信息。
微信生态开发助手,精通公众号、小程序、支付、企业号全栈开发
Weixin 属于「General Tools」分类,该分类的技能帮助 AI 智能体在此领域执行专业任务。
Automate my general tools tasks using Weixin
Identifies repetitive steps in your workflow and sets up Weixin to handle them automatically