hbuilder 调起applePay支付
项目流程,
1,vue 编写基本项目。
2,hbuilder 打包成本地资源包,
3,xcode 打包成ipa文件
查看hbuilder 文档没有完整的流程,只能这里找一点哪里找一点,然后拼凑,在一起项目的已完成,
开始配置,
1 引用
通过 plus.payment.getChannels 获取支付通道放在created() 生命周期里
plusReady() {
let _this = this;
// uni - app中将此function里的代码放入vue页面的onLoad生命周期中;
// 获取支付通道;
plus.payment.getChannels(
function(channels) {
for (var i in channels) {
var channel = channels[i];
if (channel.id === "appleiap") {
_this.appleChannel = channel;
}
}
},
function(e) {
console.log("获取支付通道失败:" + e.message);
}
);
},
2 配置 app 后台 价格
登录appstoreconnect.apple.com 点击app,选择需要applepay 的app 点击左边管理
点击+号
选择项目
填写 名称和产品ID 重点是产品ID ,这个将在代码中使用
这里的ids 数组为上图填写的ID 获取苹果商品列表
applePay() {
var ids = ["商品1", "商品2"];
// iap 为刚刚获取的`appleiap`支付通道
iap.requestOrder(
ids,
function(e) {
// 获取订单信息成功回调方法
console.log("requestOrder success: " + JSON.stringify(e));
},
function(e) {
// 获取订单信息失败回调方法
console.log("requestOrder failed: " + JSON.stringify(e));
}
);
},
支付
applePayment() {
let _this = this;
_this.RestoreFlag(false); // 实际应用请将标记存储在 storage 中
console.log();
plus.payment.request(
_this.appleChannel,
{
productid: _this.ids[_this.index],
username: _this.token // 用户标识
optimize: true // 设置 optimize: true 解决丢单问题
},
function(result) {
// 支付成功,result 为 IAP商品交易信息对象 IAPTransaction 需将返回的支付凭证传给后端进行二次认证
},
function(e) {
Toast.clear();
// 如果支付失败,需要标记 restoreFlag = true;
// 支付失败的时候需要调用一下 restoreComplateRequest 方法
restoreComplateRequest();
}
);
},
至此代码完成 文档地址文档地址
配置hbuilder
下一步配置xcode(不配置会出现html5+runtime 打包时未添加支付模块)
在下载 的ios SDK 中找到 liblibPayment.a 和libIAPPay.a配置说明
至此配置完成下图为SDK 中的说明