基於Bmob在小程序端實現一鍵支付教程:html
var openId = Bmob.User.current().get('authData').weapp.openid;
var that = this;
Bmob文檔沒提,但看到控制檯報沒有that定義,也就天然會加上了git
未認證會報 code: 10012, message: "your credit info must verify ok."小程序
認證入口:https://bmob.cn/account/info微信
實名認證.pngapp
價目表:http://bmob.cn/prices函數
應用配置->微信小程序賬號服務配置this
pay-config.pngspa
var that = this;var openId = Bmob.User.current().get('authData').weapp.openid;// console.log(openId);//傳參數金額,名稱,描述,openidBmob.Pay.wechatPay(0.01, '名稱1', '描述', openId).then(function (resp) { console.log('resp'); console.log(resp); that.setData({ loading: true, dataInfo: resp }) //服務端返回成功 var timeStamp = resp.timestamp, nonceStr = resp.noncestr, packages = resp.package, orderId = resp.out_trade_no,//訂單號,如需保存請建表保存。 sign = resp.sign; //打印訂單號 console.log(orderId); //發起支付 wx.requestPayment({ 'timeStamp': timeStamp, 'nonceStr': nonceStr, 'package': packages, 'signType': 'MD5', 'paySign': sign, 'success': function (res) { //付款成功,這裏能夠寫你的業務代碼 console.log(res); }, 'fail': function (res) { //付款失敗 console.log('付款失敗'); console.log(res); } }) }, function (err) { console.log('服務端返回失敗'); console.log(err.message); // common.showTip(err.message, 'loading',{},6000); console.log(err); });
文檔出處:http://docs.bmob.cn/data/wechatApp/b_developdoc/doc/index.html#小程序支付.net
甩掉PHP諸多SDK,拋開服務端配置,不用雲函數,不用雲引擎,Bmob一行代碼搞定預下單,這酸爽,簡直了!code
源碼下載:http://git.oschina.net/laeser/dinner