前言

uniapp苹果内购

流程

  1. let iapChannel;
  2. let IAPOrders = ['test1', 'test2', 'test3'];//商品id
  3. let id;
  4. let username = '';
  5. plus.payment.getChannels( ( channels ) => {
  6. console.log('@@@@getChannels@@@@', JSON.stringify(channels));
  7. for (var i in channels) {
  8. if (channels[i].id == 'appleiap') {
  9. iapChannel = channels[i];
  10. iapChannel.requestOrder(IAPOrders, ( event ) => {
  11. console.log('@@@@requestOrder@@@@', JSON.stringify(event));
  12. for (var index in event) {
  13. var OrderItem = event[index];
  14. id = OrderItem.productid;
  15. console.log('@@@@info@@@@', OrderItem.title + "Price:" + OrderItem.price + "Description:" + OrderItem.description + "ProductID:" + OrderItem.productid);
  16. plus.payment.request(iapChannel, {
  17. "productid": id,//商品标识
  18. "username": '',//购买用户昵称
  19. "quantity": 1//购买数量
  20. }, ( result ) => {
  21. console.log('@@@支付成功@@@', JSON.stringify(result));
  22. self.getInfo();
  23. //TODO
  24. }, ( e ) => {
  25. console.log('@@@支付失败@@@', "更多错误信息请参考支付(Payment)规范文档:http://www.html5plus.org/#specification#/specification/Payment.html", null, "支付失败:" + e.code);
  26. });
  27. }
  28. }, ( errormsg ) => {
  29. plus.nativeUI.alert(JSON.stringify(errormsg.message));
  30. console.log('@@@@获取支付通道失败1@@@@', JSON.stringify(errormsg.message));
  31. });
  32. }
  33. }
  34. }, ( e ) => {
  35. console.log('@@@@获取支付通道失败2@@@@', JSON.stringify(e.message));
  36. });

参考

https://uniapp.dcloud.io/api/plugins/payment?id=faq
https://ask.dcloud.net.cn/article/497
http://www.html5plus.org/doc/zh_cn/payment.html#plus.payment.PaymentChannel.requestOrder