1.用户申请微信开放平台申请移动应用
ps:移动应用申请时包名必须与打包app包名相同,
签名需要通过java的keytool工具去生成md5签名(注意微信使用的是md5签名) java的版本为jdk-6u43-windows
高版本的工具只能生成SHA1和SHA256这俩个微信支付用不了
<script type="text/javascript">
var pays = {};
var PAYSERVER = null;
function plusReady() {
let self = plus.webview.currentWebview();
let [waybill_sn, waybill_id] = [self.waybill_sn, self.waybill_id];
console.log(waybill_sn)
console.log(waybill_id)
// 获取支付通道
plus.payment.getChannels(function(channels) {
var content = document.getElementById('dcontent');
var info = document.getElementById('info');
var txt = '支付通道信息:';
for(var i in channels) {
var channel = channels[i];
if(channel.id == 'qhpay' || channel.id == 'qihoo') { // 过滤掉不支持的支付通道:暂不支持360相关支付
continue;
}
pays[channel.id] = channel;
txt += 'id:' + channel.id + ', ';
txt += 'description:' + channel.description + ', ';
txt += 'serviceReady:' + channel.serviceReady + '; ';
var de = document.createElement('div');
de.setAttribute('class', 'button');
de.setAttribute('onclick', 'pay(this.id)');
de.id = channel.id;
de.innerText = channel.description + '支付';
content.appendChild(de);
checkServices(channel);
}
info.innerText = txt;
}, function(e) {
ddsd.log('获取支付通道失败:' + e.message);
});
PAYSERVER = ddsd.ddsdAjax + 'Waybill/getWaybillPayInfo?id='+waybill_id+'&session3rd='+ddsd.session3rd()+'&waybill_sn='+waybill_sn+'&setTradeType=app&payid=WxPay'
}
document.addEventListener('plusready', plusReady, false);
// 检测是否安装支付服务
function checkServices(pc) {
if(!pc.serviceReady) {
var txt = null;
switch(pc.id) {
case 'alipay':
txt = '检测到系统未安装“支付宝快捷支付服务”,无法完成支付操作,是否立即安装?';
break;
default:
txt = '系统未安装“' + pc.description + '”服务,无法完成支付,是否立即安装?';
break;
}
plus.nativeUI.confirm(txt, function(e) {
if(e.index == 0) {
pc.installService();
}
}, pc.description);
}
}
var w = null;
function pay(id) {
if(w) {
return;
}
ddsd.log('----- 请求支付 -----');
var url = PAYSERVER;
var appid = plus.runtime.appid;//此处的appid为应用包的appid 真机调试永远为HBuilder打包后为该应用真实包名
if(navigator.userAgent.indexOf('StreamApp') >= 0) {
appid = 'Stream';
}
url += '&appid='+ appid +'&total=0.01';
w = plus.nativeUI.showWaiting();
// 请求支付订单
var amount = document.getElementById('total').value;
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
switch(xhr.readyState) {
case 4:
w.close();
w = null;
if(xhr.status == 200) {
ddsd.log('----- 请求订单成功 -----');
var order = xhr.responseText
plus.payment.request(pays[id], order, function(result) {
ddsd.log('----- 支付成功 -----');
plus.nativeUI.alert('支付成功:感谢你的支持,我们会继续努力完善产品。', function() {
back();
}, '捐赠');
}, function(e) {
ddsd.log('----- 支付失败 -----');
plus.nativeUI.alert('更多错误信息请参考支付(Payment)规范文档:http://www.html5plus.org/#specification#/specification/Payment.html', null, '支付失败:' + e.code);
});
} else {
ddsd.log('----- 请求订单失败 -----');
plus.nativeUI.alert('获取订单信息失败!', null, '捐赠');
}
break;
default:
break;
}
}
xhr.open('GET', url );
ddsd.log('请求支付订单:' + url);
xhr.send();
}
</script>
请求url
http://ddsd2.ittun.com/worker.php/Waybill/getWaybillPayInfo?id=1054996865944260608&session3rd=session5bd01de5290cd&waybill_sn=1540682647330&setTradeType=app&payid=WxPay&appid=HBuilder&total=0.01
开始打包
包名必须和微信开放平台相同
证书别名为申请密钥使用的别名
密码为申请秘钥的密码
文件为申请后的证书文件
申请秘钥步骤为
1.下载1.6版本java
2.进入jdk下bin 使用
keytool -genkey -alias xxx -keyalg RSA -keysize 1024 -keypass ddsd123456 -validity 3500 -keystore c:\key\xxx.keystore
创建密钥
3.keytool -list -v -keystore c:\key\xxx.keystore
使用当前命令查看密钥信息
最要的一定要真机运行 一定要真机运行 一定要真机运行 一定要真机运行 一定要真机运行 一定要真机运行 一定要真机运行 一定要真机运行 一定要真机运行
最重要的一定要把微信缓存清理一下 不行就卸了重装 缓存是个坑 记得清缓存 记得清缓存 记得清缓存 记得清缓存
还有不懂的邮箱是我qq 1035355110