字节小游戏SDK-ios切支付方案
目录
字节小游戏SDK-ios切支付方案
一般字节小游戏和ios是不允许调起第三方支付的,但是有了字节内部的api,可以实现调隐藏api实现第三方支付功能。
openWebview API 接口文档
tt.openWebview
创建实例 Webview 实例, 该 Webview 的大小默认为 {left: -1, right: -1, width: 1, height: 1} 且不能修改
语法
tt.openWebview(options);
返回值
回调参数为 Webview 类型,属性参考 Webview 说明:
参数说明
options 为 object 类型,属性如下:
属性名 | 类型 | 默认值 | 必填 | 说明 |
url | string | 无 | 是 | 跳转的 URL 地址, 域名必须为 wx.tenpay.com |
referer | string | 无 | 是 | 商户申请微信 H5 支付时提交的授权域名,用户拉起微信支付后,无论支付结果如何都会跳转到 Safari 中显示该页面 |
回调成功
返回值为 Webview 对象,类型为 object,属性如下:
属性名 | 类型 | 默认值 | 必填 | 说明 |
close | fuction | 无 | 是 | 用于关闭打开的 Webview |
errMsg | string | 无 | 是 | “openWebview:ok " |
回调失败
object 类型,属性如下:
属性名 | 类型 | 默认值 | 必填 | 说明 |
errMsg | string | 无 | 是 | “openWebview:fail " + 详细错误信息 |
示例代码
let params = {
url:'https://wx.tenpay.com/cgi-bin/mmpayweb-bin/checkmweb?prepay_id=wx09115922286166a73ff1776308e32a0000&package=2514622250',
referer: 'microapp.bytedance.com',
success(res: any) {
console.log('open Webview success!', res);
webview = res;
},
fail(res: any) {
console.log('open Webview fail!', res);
},
}
tt.openWebview(params);
小游戏回到前台时,会自动关闭上次打开的 Webview
Webview
tt.openWebview 函数返回对象,包含的属性如下
属性名 | 类型 | 说明 |
close | function | 用于关闭打开的 Webview |
Webview.close
为了防止意外的情况导致跳转微信失败,建议调用tt.openWebview 成功之后定时关闭此窗口
语法
Webview.close(options);
参数说明
回调成功
object 类型,属性如下:
,属性如下:
属性名 | 类型 | 默认值 | 必填 | 说明 |
errMsg | fuction | 无 | 是 | “Webview.close:ok " |
回调失败
object 类型,属性如下:
属性名 | 类型 | 默认值 | 必填 | 说明 |
errMsg | string | 无 | 是 | “Webview.close:fail " + 详细错误信息 |
示例代码
let params = {
url:'https://wx.tenpay.com/cgi-bin/mmpayweb-bin/checkmweb?prepay_id=wx09115922286166a73ff1776308e32a0000&package=2514622250',
referer: 'https://microapp.bytedance.com',
success(res: any) {
console.log('open Webview success!', res);
webview = res;
// cocos 写法,其他平台注意调整
setTimeout(()=>{
console.log('setTimeout close webview');
let params2 = {
success(res: any) {
console.log('timeout close Webview success!', res);
},
fail(res: any) {
console.log('timeout close Webview fail!', res);
},
}
webview.close(params2);
},2000) ;
},
fail(res: any) {
console.log('open Webview fail!', res);
},
}
tt.openWebview(params);