
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
wechat-node-sp-fix
Advanced tools
微信API for node.js,目前主要支持小程序及微信支付相关接口
微信小程序官方文档:https://developers.weixin.qq.com/miniprogram/dev/api/
微信支付官方文档:https://pay.weixin.qq.com/wiki/doc/api/wxa/wxa_api.php?chapter=7_7&index=5
npm install wechat-node-sp
初始化
var weChatApi = require("wechat-node-sp");
var wechatApi = weChatApi({
appId,
appSecret,
mch_id,//微信商户平台ID
pfx: fs.readFileSync("./apiclient_cert.p12"),//微信商户平台支付正式
payKey//微信商户平台API秘钥
})
微信登录相关
//微信登录
var result = await wechatApi.login(code);
if (result.status === 200 && !result.data.errcode) {
var data = {
openid: result.data.openid,
session_key: result.data.session_key,
unionid: result.data.unionid
}
console.log(data);
}
//获取用户信息
var userInfo = await wechatApi.getWechatUserInfo(sessionKey, encryptedData, iv);
console.log(userInfo);
获取微信token
var result = await wechatApi.getAccessToken();
if (result.data && !result.data.errcode) {
var token = result.data.access_token;
console.log(token);
}
微信小程序下单,获取支付参数
var params = {
body: "支付测试",
notify_url: "https://PayNotify",
openid: "openid",
out_trade_no: "111111111111111111111111",
spbill_create_ip: "客户端ip",
total_fee: 1,
trade_type: "JSAPI",
};
var result = await wechatApi.getMiniProgramPayParams(params)
console.log(result);
退款接口
var params = {
out_refund_no: "",//退款商户订单号,商户生成
out_trade_no: "",//需退款订单的商户订单号(二选一)
transaction_id:""//需退款订单的微信订单号(二选一)
refund_fee: 1,
total_fee: 1
}
var result = await wechatApi.refund(params);
console.log(result)
查询订单
// 通过商户订单号查
var result = await wechatApi.queryOrder( out_trade_no);
// 通过微信订单号查
var result = await wechatApi.queryOrder(transaction_id);
小程序模板推送
var msg={
"touser": "openId",
"template_id": "模板id",
"form_id": "formid",//表单提交场景下,为 submit 事件带上的 formId;支付场景下,为本次支付的 prepay_id
"page": "pages/test",//点击模板消息跳转页面,可不填
"data": {
"keyword1": {
"value": "推送测试",
"color": "#173177"
},
"keyword2": {
"value": "推送测试",
"color": "#173177"
}
...
}
}
}
var result = await wechatApi.sendMiniProgramTemplate(token, msg);
console.log(result)
商户服务端处理微信的回调(koa为例)
// 支付成功异步回调
router.use('/wxpay/paynotify',async function paynotify(ctx, next){
//获取微信推送数据
var result = await wechatApi.getWechatNoticeData(ctx.req);
//验证消息是否来自微信
var isWxMessage = await Wechat.WechatAuth(result);
//通知微信处理结果
await Wechat.responseSuccess(ctx,"success");//成功
await Wechat.responseFail(ctx,"fail"); //失败
});
// 退款异步回调
router.use('/wxpay/refundnotify', async function refundnotify(ctx, next){
var result = await wechatApi.getRefundData(ctx.req);
//通知微信处理结果
await Wechat.responseSuccess(ctx,"success");//成功
await Wechat.responseFail(ctx,"fail"); //失败
});
FAQs
Node.js 微信小程序及微信公众平台 API
The npm package wechat-node-sp-fix receives a total of 0 weekly downloads. As such, wechat-node-sp-fix popularity was classified as not popular.
We found that wechat-node-sp-fix demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.