Wexin payments plugin import from http://wex5.com/
Send WeChat payment request, only test the android version right now.
cordova plugin add https://github.com/ZhichengChen/cordova-plugin-wechat-payments
-
Go to WeChat Open Platfrom, authentication WeChat developer;
-
After authenticationed, create a mobile application, remeber your AppID;
-
Modify the app's application sign and application packagename to yours then remeber them;
-
Apply the WeChat payments capability;
-
Your will received the WeCaht Merchant Platform account by email after the apply approved, follow the instraction in the email finish your authentication;
-
In this page, click
Setting PassPhrase
button, then fill the api key with 32 bit passphrase, remeber your merchat id and api key;
-
Open the
plugins/android.json
, change the $weixin_api_key to your AppID; -
Open the
src/android/com/justep/base/Constants.java
, fill the PACKNAME, ACTIVITYCLASSNAME, APPNAME with proper value, and fill the APPID, PARTNERID, APIKEY with AppId, merchat id, api key; -
Js code
function randomString(len) { var chars = '1234567890'; var maxPos = chars.length; var pwd = ''; for (i = 0; i < len; i++) { pwd += chars.charAt(Math.floor(Math.random() * maxPos)); } return pwd; } function pay() { var weixin = navigator.weixin; var notifyUrl = "http://www.justep.com"; var traceID = randomString(6); var traceNo = randomString(9); weixin.generatePrepayId({ "body" : "x5外卖", "feeType" : "1", "notifyUrl" : notifyUrl, "totalFee" : "1", "traceId" : traceID, "tradeNo" : traceNo }, function(prepayId) { weixin.sendPayReq(prepayId, function(message) { console.log(message); var responseCode = parseInt(message); if (responseCode === 0) { alert("微信支付成功"); } else if (!isNaN(responseCode)) { alert("微信支付失败(-13)"+responseCode); } else { alert("微信支付失败(-10)"); } }, function(message) { alert("微信支付失败(-10)"); }); }, function(message) { console.log(message); alert("微信支付失败(-11)"); } ); }
-
Make sure the package name is same with application packagename, and release your application with the keystore.