微信支付官方「小程序发券插件」(≤1.1.3) 数据签名概要
source link: https://thenorthmemory.github.io/post/the-busifavor-data-signature-by-using-the-official-wechat-miniprogram-plugin/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
微信支付官方「小程序发券插件」(≤1.1.3) 数据签名概要
先来看看「小程序发券插件」所需参数,yaml格式如下:
type: object
required:
- send_coupon_params
- sign
- send_coupon_merchant
properties:
bindcustomevent:
type: string
description: 自定义事件
send_coupon_params:
type: array
description: 发券参数
items:
type: object
required:
- stock_id
- out_request_no
properties:
stock_id:
type: string
description: 批次号
example: abc123
out_request_no:
type: string
description: 发券凭证
example: '1234567'
sign:
type: string
description: 签名
example: 9A0A8659F005D6984697E2CA0A9CF3B79A0A8659F005D6984697E2CA0A9CF3B7
send_coupon_merchant:
type: string
description: 发券商户号
example: '10016226'
转换成数据结构即:
{
bindcustomevent: 'getcoupon',
send_coupon_params: [
{out_request_no:'1234567',stock_id:'abc123'}
],
send_coupon_merchant: '10016226'
}
签名时,文档说明是需要把上述参数,以key
下标从0开始拉平成1维对象,即:
{
out_request_no0: '1234567',
stock_id0: 'abc123',
send_coupon_merchant: '10016226'
}
参数key
下标以index
记录了顺序,最大支持十张券刚好是0-9,有点儿 Array.prototype.flatMap()
的味道,但不完全是。
转换函数如下:
// 可单独抽离成模块
exports.busiFavorFlat = ({send_coupon_params, send_coupon_merchant = []} = {}) => {
return {
send_coupon_merchant,
...(send_coupon_params || []).reduce((des, row, idx) => (Object.keys(row).map(one => des[`${one}${idx}`] = row[one]), des), {}),
}
}
使用如下:
const responder = {
send_coupon_params: [
{out_request_no:'1234567',stock_id:'abc123'},
{out_request_no:'7654321',stock_id:'321cba'},
],
send_coupon_merchant: '10016226'
}
const waitToSign = busiFavorFlat(responder)
以 v2版nodejs签名代码为例,把以上输出,代入签名,大功告成,如下~
// let key = 'exposed_your_key_here_have_risks'
responder.sign = signHmacSha256(toSignString(ksort(waitToSign), key), key)
// console.info(responder.sign)
// 20FB971D442A119C85CA1A49DBDEA61A14944D98AFC1D2B040030C5C8792A83A
// 签名及数据结构,以JSON串发送给小程序端
// server.response.toMiniProgram(JSON.stringify(responder))
文章首发于微信开发者社区。
文章作者 James
上次更新 2020-07-21
Recommend
-
83
微信小程序开放插件功能 开发效率提升门槛降低
-
48
【TechWeb报道】7月4日消息,昨日,有网友在国外安全社区公布了微信支付官方SDK(软件工具开发包)存在的严重漏洞,此漏洞可导致商家服务器被入侵,一旦攻击者获得商家的关键安全密钥,就可以通过发送伪造信息来欺骗商家而无需付费购买任何东西。
-
31
美张-发券助手 - 每个人都能轻松发券,券可分销 - NEXT
-
8
优惠券需求:从发券到用券怎么推动? 谁偷吃了小饼干 2022-03-28 5 评论...
-
5
使用Guzzle标准包,向微信支付V3官方中间件添加媒体上传类 2020-05-31 wechat
-
4
手机厂商“最血腥”618:控盘、发券,一切为了榜单数据 于惠如 发表于 2022年06月18日 10:06...
-
4
...
-
3
作者 | 齐建朝 近几年春节期间,抖音都会为用户带来各式各样的春节活动,每年都会有数亿用户参与其中。2022 年春节,抖音支付也参与了春节活动,面向海量用户发放抖音支付券,帮助用户在抖音春节活动中获得更好体验。对抖音支付来说,这是一个很大的挑战,...
-
0
微信支付v3接口的 官方 Java SDK
-
8
...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK