用户删除商家名片会员卡事件(MEMBERCARDSP.USER_CARD.DELETE)通知(JSON)
当会员卡批次或者用户的会员卡发生变化时,微信会把相关事件结果和用户信息发送给商户,商户需要接收处理,并按照文档规范返回应答。
注意:
- 若商户应答回调接收成功,微信支付将不再重复发送该回调通知。若因网络或其他原因,商户收到了重复的回调通知,请按正常业务流程进行处理并应答。
- 对后台通知交互时,如果微信收到应答不是成功或超时,微信认为通知失败,微信会通过一定的策略定期重新发起通知,尽可能提高通知的成功率,但微信不保证通知最终能成功。(通知频率为每隔60秒重试一次,最多重试11次)
请求参数 | 类型 | 描述 |
---|---|---|
headers | object | 通知的头参数 |
Content-Type | string | application/json |
Request-ID | string | 通知的唯一标识 |
Wechatpay-Nonce | string | 数据签名使用的随机串 |
Wechatpay-Serial | string | 微信支付公钥ID/平台证书序列号 |
Wechatpay-Signature | string | 签名串 |
Wechatpay-Signature-Type | string | 签名算法WECHATPAY2-SHA256-RSA2048 枚举值 |
Wechatpay-Timestamp | string | 时间戳 |
body | object | 通知的JSON 数据结构 |
id | string | 通知的唯一ID |
create_time | string | 通知创建的时间 |
event_type | string | 通知的类型MEMBERCARDSP.USER_CARD.DELETE 枚举值 |
resource_type | string | 通知的资源数据类型 |
summary | string | 回调摘要 |
resource | object | 通知资源数据 |
original_type | string | 原始回调类型 |
algorithm | string | 对数据进行加密的加密算法AEAD_AES_256_GCM 枚举值 |
associated_data | string | 数据加密的附加数据 |
nonce | string | 加密使用的随机串 |
ciphertext | string | 加密后的密文数据 |
event_type | string | 事件类型MEMBERCARDSP.USER_CARD.DELETE 枚举值 |
event_time | string | 激活时间 |
user_card_code | string | 会员卡code |
card_id | string | 会员卡模板ID |
openid | string | 用户标识 |
card_color | string | 卡背景颜色 |
card_picture_url | string | 卡背景图URL |
brand_id | string | 品牌ID |
card_type | string | 会员卡类型PURCHASE | NORMAL | BALANCE 枚举值之一 |
membership_number | string | 会员卡编号 |
phone_number | string | 加密的手机号 |
level | string | 等级 |
valid_date_information | object | 会员卡有效期 |
type | string | 有效期类型FIX_TIME_RANGE | FIX_TERM | PERMANENT 枚举值之一 |
available_begin_time | string | 有效期开始时间 |
available_end_time | string | 有效期结束时间 |
available_day_after_receive | integer | 生效后N天内有效 |
pickup_time | string | 领取时间 |
user_information | object | 用户开卡时填写的个人信息 |
common_field_list | object[] | 平台提供的通用开卡信息字段 |
name | string | 平台提供的通用开卡信息字段USER_FORM_FLAG_SEX | USER_FORM_FLAG_NAME | USER_FORM_FLAG_BIRTHDAY | USER_FORM_FLAG_ADDRESS | USER_FORM_FLAG_EMAIL | USER_FORM_FLAG_CITY 枚举值之一 |
value | string | 加密的用户开卡时填写的个人信息 |
custom_field_list | object[] | 商户自定义的开卡信息字段 |
name | string | 字段名称 |
values | string[] | 字段值 |
user_chosen_values | string[] | 加密的用户选择的字段值列表 |
attach | string | 商家数据包 |
user_card_state | string | 用户会员卡状态NOT_EFFECTIVE | EFFECTIVE | EXPIRED | UNAVAILABLE | DELETE 枚举值之一 |
invalid_reason | string | 作废原因 |
invalid_time | string | 作废时间 |
php
// 使用Psr标准规范,示例如何处理(取值、验签、解密)「回调通知」事件,WebServer不同,用法略有差异,供参考实现。
function webhookProcessor(\Psr\Http\Message\RequestInterface $request,
array $platformPublicKeyMap, string $apiv3Key): array {
if (!\count($platformPublicKeyMap)) {
throw new \WeChatPay\Exception\InvalidArgumentException('平台证书或者平台公钥数组不能为空');
}
if (\strlen($apiv3Key) !== 32) {
throw new \WeChatPay\Exception\InvalidArgumentException('APIV3密钥为32字节,长度不对');
}
if (!($request->hasHeader(\WeChatPay\WechatpayNonce)
&& $request->hasHeader(\WeChatPay\WechatpaySerial)
&& $request->hasHeader(\WeChatPay\WechatpaySignature)
&& $request->hasHeader(\WeChatPay\WechatpayTimestamp))) {
throw new \WeChatPay\Exception\InvalidArgumentException('通知的头参数缺失必要参数');
}
// 检查通知的时间偏移量,允许5分钟之内的偏移
[$inWechatpayTimestamp] = $request->getHeader(\WeChatPay\WechatpayTimestamp);
if (\WeChatPay\MAXIMUM_CLOCK_OFFSET < \abs(
\WeChatPay\Formatter::timestamp() - (int)$inWechatpayTimestamp)) {
throw new \WeChatPay\Exception\InvalidArgumentException('通知头参数的时间偏移量超过可信阈值');
}
// 检查通知的平台证书/平台公钥实例是否存在
[$inWechatpaySerial] = $request->getHeader(\WeChatPay\WechatpaySerial);
if (!\array_key_exists($inWechatpaySerial, $platformPublicKeyMap)) {
throw new \WeChatPay\Exception\InvalidArgumentException('通知头参数的证书序列号/公钥ID本地不存在');
}
// 验证通知的数据签名
[$inWechatpaySignature] = $request->getHeader(\WeChatPay\WechatpaySignature);
[$inWechatpayNonce] = $request->getHeader(\WeChatPay\WechatpayNonce);
$inBody = (string)$request->getBody();
if (!\WeChatPay\Crypto\Rsa::verify(
\WeChatPay\Formatter::joinedByLineFeed($inWechatpayTimestamp, $inWechatpayNonce, $inBody),
$inWechatpaySignature, $platformPublicKeyMap[$inWechatpaySerial]
)) {
throw new \WeChatPay\Exception\InvalidArgumentException('通知头参数的数据签名校验未通过');
}
// 转换通知的JSON文本消息为PHP Array数组
$inBodyArray = (array)\json_decode($inBody, true);
// 使用PHP7+的数据解构语法,从Array中解构并赋值变量
['resource' => [
'ciphertext' => $ciphertext,
'nonce' => $nonce,
'associated_data' => $aad
]] = $inBodyArray;
// 加密文本消息解密,有可能解密异常(eg: 平台探测流量)会抛 \UnexpectedValueException
$inBodyResource = \WeChatPay\Crypto\AesGcm::decrypt($ciphertext, $apiv3Key, $nonce, $aad);
// 把解密后的文本转换为PHP Array数组
$inBodyResourceArray = (array)\json_decode($inBodyResource, true);
// 把解密后的数组定义为'original_data'函数返回
$inBodyArray['resource']['original_data'] = $inBodyResourceArray;
return [
'headers' => $request->getHeaders(),
'body' => $inBodyArray
];
}
// do your business
// ...
// ...
$json = \json_encode([
'code' => 'SUCCESS',
'message' => 'OK'
]);
应答规范 | 类型 | 描述 |
---|---|---|
status | number | HTTP 状态码20X 4XX 5XX 枚举值之一 |
body | object | 应答的JSON 数据结构 |
code | string | 业务处理状态码SUCCESS | FAIL 枚举值之一 |
message | string | 业务处理附加信息 |
参阅 官方文档