hbuilder 调起applePay支付

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 中的说明在这里插入图片描述
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值