参考文档:http://www.html5plus.org/doc/zh_cn/payment.html

申请内购项目摘自 https://www.jianshu.com/p/1e79bfbe46e2

<template>
<div id="app">
<h3 @click="pay(ids[0])"></h3>
</div>
</template> <script>
export default {
data() {
return {
iap: {},
ids: ["donation6","donation"],//应用内购项目,需要申请
}
},
created() {
document.addEventListener("plusready", function() {
//console.log("所有plus api都应该在此事件发生后调用,否则会出现plus is undefined。"
});
document.addEventListener("plusready",this.plusReady(),false);
},
methods: {
plusReady() {
let _this = this;
// 获取支付通道
plus.payment.getChannels(
function(channels) {
for (var i in channels) {
var channel = channels[i];
// 用于标识支付通道: "alipay" - 表示支付宝; "wxpay" - 表示微信支付; "appleiap" - 表示苹果应用内支付; "qhpay" - 表示360聚合支付(仅360手助流应用环境下支持)。
if (channel.id === "appleiap") {
_this.iap = channel;
_this.requestOrder();
}
}
},
function(e) {
console.log("获取支付通道失败:" + e.message);
}
);
},
requestOrder() {
let _this = this;
plus.nativeUI.showWaiting("检测支付环境...");
_this.iap.requestOrder(_this.ids,function(e) {
plus.nativeUI.closeWaiting();
console.log("requestOrder success: " + JSON.stringify(e));
},function(e) {
console.log("requestOrder failed: " + JSON.stringify(e));
plus.nativeUI.closeWaiting();
plus.nativeUI.confirm("错误信息:" + JSON.stringify(e),
function(e) {
if (e.index == 0) {
_this.requestOrder();
} else {
// back();
}
},
"重新请求支付",["确定", "取消"]
);
}
);
},
// 支付
pay(id) {
let _this = this;
plus.nativeUI.showWaiting("", {style: "black",background: "rgba(0,0,0,0)"});
plus.payment.request(_this.iap,{ productid: id },function(result) {
plus.nativeUI.closeWaiting();
_this.fetchPayStatus(result);
},
function(e) {
console.log("错误信息",e)
plus.nativeUI.closeWaiting();
plus.nativeUI.alert(
"错误信息:" + e.message,
null,
"支付失败:" + e.code
);
}
);
},
fetchPayStatus(result) {
// let ordercode = window.location.href.split("ordercode=")[1]; //收集支付需要专递的参数
// console.log("ordercode", ordercode);
axios({
method: "post",
url: "https://pay.52xxxxxdd.cn/PaiyxApxxxxxple/appxxxxxxcion",//换成自己请求支付的接口
headers: {
"Content-Type": "application/x-www-form-urlencoded",
Accept: "application/json, text/plain, */*"
},
data: `transactionId=${result.transactionIdentifier}&receipt=${result.transactionReceipt}`,//传递的参数
})
// .then(res => {
// if(res.data.code === 1){
// window.location.href = `${window.location.origin}/bzjp/detail.html?ordercode=${ordercode}`;
// }
// });
},
}
}
</script>

最新文章

  1. 用django创建一个项目
  2. 读取xml文件报错:Invalid byte 2 of 2-byte UTF-8 sequence。
  3. 设置surfaceView的背景为透明
  4. FireFox下上传控件的显示问题
  5. oracle 10g 学习之视图、序列、索引、同义词(9)
  6. NET下RabbitMQ实践[实战篇]
  7. JavaScript学习总结【8】、面向对象编程
  8. BZOJ 1110: [POI2007]砝码Odw( 贪心 )
  9. log4net学习目录
  10. 开发环境FAQ
  11. 全国交通咨询系统 by C++ on Linux
  12. border三角形阴影(不规则图形阴影)和多重边框的制作
  13. springboot集成redis(mybatis、分布式session)
  14. PhpStudy如何开启Apache的gzip压缩功能?
  15. 百度技术沙龙之2013-2&amp;3
  16. maven profile实现多环境配置
  17. Html中,id、name、class、type的区别
  18. Ubuntu学习
  19. oracle中计算百分比,并同时解决小数点前0不显示的问题
  20. 在 Windows 8、Windows 10 桌面模式下的 .NET Framework 程序中,引用 Windows.Runtime 的 API。

热门文章

  1. 忘记zip密码咋办?python在手密码我有
  2. nacos-server安装、运行 (docker)
  3. Python3 fake_useragent 模块的使用和报错解决方案
  4. ip地址掩码和位数对应关系表、子网掩码、网络地址、主机地址-yellowcong
  5. golang 内存监控
  6. Char.IsDigit与Char.IsNumber的区别
  7. 多线程、线程池、线程创建、Thread
  8. 进程间之异步通信:信号Signal
  9. servlet 标红的错误笔记
  10. (转)JVM原理讲解和调优