uniapp 苹果内购支付

2,783 阅读4分钟

iOS 内购设置AppStore中协议、税务和银行

  1. 登录AppStore Connect 中心

    ![](https://upload-images.jianshu.io/upload_images/19826068-b95747d594305ffb.png?imageMogr2/auto-orient/strip|imageView2/2/w/981)
  2. 用短信或绑定的设备进行双重认证

    ![](https://upload-images.jianshu.io/upload_images/19826068-1f3c48727865cc7f.png?imageMogr2/auto-orient/strip|imageView2/2/w/767)
  3. 同意服务协议

    ![](https://upload-images.jianshu.io/upload_images/19826068-175a206980188fa9.png?imageMogr2/auto-orient/strip|imageView2/2/w/969)
  4. 找到协议、税务和银行业务

    ![](https://upload-images.jianshu.io/upload_images/19826068-5a38f161a63e875b.png?imageMogr2/auto-orient/strip|imageView2/2/w/996)
  5. 免费App已经正常了,付费App点后面操作的查看并同意条款

    ![](https://upload-images.jianshu.io/upload_images/19826068-b5f60800a44a1d18.png?imageMogr2/auto-orient/strip|imageView2/2/w/1125)
  6. 确认条款后,就会看到设置税务、银行业务和联系信息

    ![](https://upload-images.jianshu.io/upload_images/19826068-d0ecea0a6be8d707.png?imageMogr2/auto-orient/strip|imageView2/2/w/1118)
  7. 进入付费App中,添加银行账户

    ![](https://upload-images.jianshu.io/upload_images/19826068-502b71fea86ce1c9.png?imageMogr2/auto-orient/strip|imageView2/2/w/1124)
  8. 添加新银行账户。这里可以是个人,也可以是公司。如果是公司时,用公司申请邓白氏编码时的英文名;个人的话写名字拼音

    ![](https://upload-images.jianshu.io/upload_images/19826068-82ed9c2e8950ab9b.png?imageMogr2/auto-orient/strip|imageView2/2/w/802)
  9. 这里有一个银行的CNAPS码,这是大陆地区每个银行的银联收款号,用苹果自带的查询都是英雄输入太麻烦的,这里用第三方联行号网查询

  10. 确认后会显示银行信息

<div>
<div>

<div>![](https://upload-images.jianshu.io/upload_images/19826068-7f776f53c67f4e95.png?imageMogr2/auto-orient/strip|imageView2/2/w/1123)</div>

</div>

</div>

11. 继续往下拉,添加选择报税表

<div>

<div>

<div>![](https://upload-images.jianshu.io/upload_images/19826068-b32dc37ab8d5613c.png?imageMogr2/auto-orient/strip|imageView2/2/w/1115)</div>

</div>

</div>

12. 报税表选择美国

<div>

<div>

<div>![](https://upload-images.jianshu.io/upload_images/19826068-cc84c6729c764d7b.png?imageMogr2/auto-orient/strip|imageView2/2/w/800)</div>

</div>

</div>

13. 填写美国报税表

<div>

<div>

<div>![](https://upload-images.jianshu.io/upload_images/19826068-05560726575ffdef.png?imageMogr2/auto-orient/strip|imageView2/2/w/710)</div>

</div>

</div>

14. 美国税务居民,选择

<div>

<div>

<div>![](https://upload-images.jianshu.io/upload_images/19826068-ea42973ac7f94943.png?imageMogr2/auto-orient/strip|imageView2/2/w/796)</div>

</div>

</div>

15. 美国是否有商业活动,选择

<div>

<div>

<div>![](https://upload-images.jianshu.io/upload_images/19826068-8afd2a7f0e1c8968.png?imageMogr2/auto-orient/strip|imageView2/2/w/812)</div>

</div>

</div>

16. 查看自己的基本信息

<div>

<div>

<div>![](https://upload-images.jianshu.io/upload_images/19826068-ac84cc61ad6e65ff.png?imageMogr2/auto-orient/strip|imageView2/2/w/801)</div>

</div>

</div>

17. 确认信息,然后在Title中输入英文签名

<div>

<div>

<div>![](https://upload-images.jianshu.io/upload_images/19826068-1f633e8d9d6ab1b9.png?imageMogr2/auto-orient/strip|imageView2/2/w/1105)</div>

</div>

</div>

18. 确认报税表信息,填写Date of Birth生日就好了,其他的可以不填

<div>

<div>

<div>![](https://upload-images.jianshu.io/upload_images/19826068-55917f7bfb5773a1.png?imageMogr2/auto-orient/strip|imageView2/2/w/924)</div>

</div>

</div>

19. Part II: Claim of Tax Treaty Benefits (If Applicable) 勾选就行了,其他可以留空

<div>

<div>

<div>![](https://upload-images.jianshu.io/upload_images/19826068-ef64e3b4ea00ef29.png?imageMogr2/auto-orient/strip|imageView2/2/w/1101)</div>

</div>

</div>

20. Part III: Certification中确认信息,并签名。最后提交

<div>

<div>

<div>![](https://upload-images.jianshu.io/upload_images/19826068-6e6082e6a7f88d56.png?imageMogr2/auto-orient/strip|imageView2/2/w/924)</div>

</div>

</div>

21. 回到协议、税务和银行业务页面,状态切换成了设置联系信息

<div>

<div>

<div>![](https://upload-images.jianshu.io/upload_images/19826068-4c36658e1e896bab.png?imageMogr2/auto-orient/strip|imageView2/2/w/1121)</div>

</div>

</div>

22. 添加联系信息

<div>

<div>

<div>![](https://upload-images.jianshu.io/upload_images/19826068-a683bacabd62d65e.png?imageMogr2/auto-orient/strip|imageView2/2/w/903)</div>

</div>

</div>

23. 完成后,回到协议、税务和银行业务页面,状态切换成了有效

<div>

<div>

<div>![](https://upload-images.jianshu.io/upload_images/19826068-8b5145cfaf943cf1.png?imageMogr2/auto-orient/strip|imageView2/2/w/1117)</div>

</div>

</div>

作者:岑吾
链接:www.jianshu.com/p/466ea6ddd…
来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

苹果内购IAP-配置内购商品

1、打开itunesconnect.apple.com

2、进入“我的app”,左上角选择“功能”

点击“+”,一步步填写即可

商品类型根据需要来写,我这边是给账户充钱,一次性消费选的是“消费类型”

字段描述

商品名称:商品叫什么名字,比如“充值98元”;

产品id:是这个商品的id,自己定义吧;

描述:那就是描述喽、、、

显示名称:保持和商品名称一样,没什么大问题

屏幕快照:购买时候的界面,截图放上去

审核备注:备注信息

最后保存即可

苹果支付,前端代码

假入你的付费内容属于虚拟商品就必须接入苹果内购、否则审核就不能通过。那么哪些内容属于虚拟商品呢。举个栗子。像视频课程、网站会员、网站内的金币这些不需要配送实物的商品就属于虚拟商品。苹果官方规定必须使用苹果IAP应用内支付,给苹果分成30%。还是比较坑的。

苹果内购流程是通过客户端接入iOS的IAP模块后,由客户端发起支付,然后再把充值数据(receipt)发给服务端,最后由服务端远程调用AppStore服务器验证。这个过程要处理好订单问题,不然可能会出现丢单的情况。

上代码,这里我是在uniapp 里接入苹果内购。以下接口可在这里查看 这里使用vue的mixins 先定义一个applePay.js 文件

export default {
  data() {
    return {
      productIds: [
        'com.xxx.xxx.xxx',//在苹果开发者平台填写的产品ID,每一个都是唯一的
      ],
      iapChannel: null,
      object_id: "",
      productId: '', //商品的标识
      appusername: '', //购买用户名称
      quantity: 1, //商品数量
      payedProductList: [], //从苹果服务器获取的已购买商品订单
    }
  },
  onHide() {
    plus.nativeUI.closeWaiting();
  },
  methods: {
    get_channel() {
      return new Promise((resolve, reject) => {
        plus.payment.getChannels((channels) => {
          console.log("获取到channel" + JSON.stringify(channels))
          for (var i in channels) {
            var channel = channels[i];
            if (channel.id === 'appleiap') {
              this.iapChannel = channel;
              resolve(channel)
            }
          }
          if (!this.iapChannel) {
            reject('暂不支持苹果 iap 支付')
          }
        }, (e) => {
          reject('获取支付通道列表失败:' + e.message)
        });
      });
    },
    // 获取已购买商品(非消耗性商品和订阅商品)
    restoreComplatePay() {
      this.payedProductList = [];
      this.iapChannel.restoreComplateRequest({}, function(response) {
        console.log(response);
      });
    },
    //从苹果服务器请求支付商品列表
    requestOrder() {
      return new Promise((resolve, reject) => {
        plus.nativeUI.showWaiting('检测支付环境...');
        this.iapChannel.requestOrder(this.productIds, function(e) { //IAP支付在调用plus.payment.request方法支付前须先向服务器请求获取商品的详细信息,否则会支付失败
          plus.nativeUI.closeWaiting();
          resolve(e)
        }, function(e) {
          plus.nativeUI.closeWaiting();
          plus.nativeUI.confirm("请求失败", function(e) {
            if (e.index == 0) {
              requestOrder();
            }
          }, '重新请求支付', ['确定', '取消']);
        });
      });
    },
    //带上当前需要支付的product_id 支付
    applePay() {
      let vm = this
      return new Promise((resolve, reject) => {
        plus.nativeUI.showWaiting('', {
          style: "black",
          background: "rgba(0,0,0,0)"
        });
        plus.payment.request(vm.iapChannel, {
          "productid": vm.productId,
          "username": vm.appusername,
          "quantity": vm.quantity,
        }, function(response) {
          plus.nativeUI.closeWaiting();
          //去服务端验证是否支付成功
          vm.$request({
            url: 'xxx',//后台验证是否支付成功
            data: {
              callback_data: JSON.stringify(response),
              object_id: vm.object_id
            },
            method: 'post',
            success: function(res) {
              console.log(res);//支付成功后的逻辑
            },
            error: function(e) {
              reject("支付失败");
            }
          })
        }, function(e) {
          plus.nativeUI.closeWaiting();
          reject("支付失败");
        });
      });
    }
  }
}