【2025年1月2日】关于腾讯云小程序平台更名为腾讯云超级应用服务的公告
控制台更新动态
Android SDK 更新动态
iOS SDK 更新动态
Flutter 更新动态
IDE 更新动态
基础库更新动态

signData、 paySig、signature)回调给小程序前端,小程序服务端签名示例请参考:signData'{"mode":"goods","buyQuantity":1,"env":0,"currencyType":"USD","platform":"android","productId":"testproductId","goodsPrice":10,"outTradeNo":"xxxxxx","attach":"testdata"}'
paySig生成,参数如下:字段 | 类型 | 描述 |
signData | string | 支付原串 |
appkey | string | 支付签名密钥(由小程序后端保存,且与 superapp 后端自行完成密钥的交换) |
method | string | 固定格式:requestMidasPaymentGameItem |
import hmacimport hashlibimport urllib.parse# signData 支付原串 注意这里 signData 需要和前端一致,原格式传递(包括空格和回车),建议后台下发,# appkey 支付密钥# method 需要签名方法 requestMidasPaymentGameItemdef gen_pay_sig(signData, appkey, method):need_encode_body = method + '&' + sign_dataprint(need_encode_body)return hmac.new(key=appkey.encode('utf-8'), msg=need_encode_body.encode('utf-8'),digestmod=hashlib.sha256).hexdigest()
signature生成,参数如下:字段 | 类型 | 描述 |
session_key | string | |
post_body | string | signData 支付原串 |
import hmacimport hashlibimport jsonimport timedef calc_signature(post_body, session_key):## 用户登录态 signature 签名算法## Args:## post_body - http POST 的数据包体## session_key - 当前用户有效的 session_key,参考 jscode2session 接口## Returns:## 用户登录态签名 signature"""need_sign_msg = post_bodysignature = hmac.new(key = session_key.encode('utf-8'), msg = need_sign_msg.encode('utf-8'),digestmod=hashlib.sha256).hexdigest()return signature
wx.requestVirtualPayment({signData: JSON.stringify({offerId: '123',buyQuantity: 1,currencyType: 'USD',productId: 'testproductId',goodsPrice: 10,outTradeNo: 'xxxxxx',attach: 'testdata',}),paySig: 'd0b8bbccbe109b11549bcfd6602b08711f46600965253a949cd6a2b895152f9d',signature: 'd0b8bbccbe109b11549bcfd6602b08711f46600965253a949cd6a2b895152f9d',mode: 'short_series_goods',success(res) {console.log('requestVirtualPayment success', res)},fail({ errMsg, errCode }) {console.error(errMsg, errCode)},})
@ProxyService(proxy = MiniOpenApiProxy.class)public class MiniOpenApiProxyImpl extends MiniOpenApiProxy {@Overridepublic void requestVirtualPayment(IMiniAppContext miniAppContext, JSONObject params, AsyncResult result) {// call your custom payment implementationboolean paySuccess = PaymentManagerV2.g().startMidasPayment(miniAppContext, params, result);// notify payment result with AsynResultif(paySuccess){result.onReceiveResult(true,successData);}else{result.onReceiveResult(false,failedData);}}}
- (void)requestVirtualPayment:(TMFMiniAppInfo *)app params:(NSDictionary *)params completionHandler:(MACommonCallback)completionHandler{[[TCMPPDemoPayManager sharedInstance] checkPreOrder:params appType:1 completionHandler:^(NSError * _Nullable err, PayResponseData * _Nullable result) {if (!err) {dispatch_async(dispatch_get_main_queue(), ^{TCMPPDemoPaymentMethodsController *payMethodVC = [[TCMPPDemoPaymentMethodsController alloc]init];payMethodVC.payResponseData = result;payMethodVC.app = app;[[[DebugInfo sharedInstance] topViewController].navigationController pushViewController:payMethodVC animated:NO];payMethodVC.completeHandle = ^(NSDictionary * _Nullable result, NSError * _Nullable error) {completionHandler(result,error);};});}}];}
文档反馈