|
本帖最后由 wangguangfan 于 2017-5-23 14:26 编辑
- </blockquote></div><div><div class="blockcode"><blockquote> //微信支付
- /**
- -23 当前环境不支持微信支付
- -20 微信支付失败
- var payDtd = $.Deferred();获取延迟对象的,用来处理异步请求后的逻辑处理
- */
- Model.prototype.payOrderByWeixinJSSDK = function(payDtd, orderID,amount) {
- if (!navigator.WxApi) {
- payDtd.reject(-33);
- return false;
- }
- var tradeNo = orderID;
- amount = amount * 100;
- var notifyUrl = location.origin + "/baas/weixin/weixin/notify";
- this.wxApi.chooseWXPay({
- body : "本地服务微购",
- mchId : "1439199202",
- notifyUrl : notifyUrl,
- outTradeNo : tradeNo,
- totalFee : amount
- }).done(function() {
- payDtd.resolve(2);
- }).fail(function() {
- payDtd.reject(-20);
- });
- };
- Model.prototype.payBtnClick = function(event){
- var payDtd = $.Deferred();
- var orderData = this.comp("orderData");
- var couponData = this.comp("couponData");
- var orderID = justep.UUID.createUUID();
- if(this.totalAmount != 0){
- this.payOrderByWeixinJSSDK(payDtd, orderID,this.totalAmount);
- }else if(this.totalAmount === 0){
- payDtd.resolve(0);
- }else{
- payDtd.reject(0);
- }
-
- if(this.totalAmount == 0){
- Baas.sendRequest({
- "url" : "/onebuyBaas/oneBuy",
- "action" : "updateOrderState",
- "async" : false,
- "params" : {
- "oid" : orderData.val("id"),
- "statue":"PLAYED",
- "couponData" : couponData.toJson({format:"simple"})
- },
- "success" : function(data) {
- justep.Util.hint("支付成功!");
- orderData.refreshData();
- }
- });
- }else{
- var pay = payDtd.promise();
- pay.always(function(code) {
- if(code == 2){
- Baas.sendRequest({
- "url" : "/onebuyBaas/oneBuy",
- "action" : "updateOrderState",
- "async" : false,
- "params" : {
- "oid" : orderData.val("id"),
- "statue":"PLAYED",
- "couponData" : couponData.toJson({format:"simple"})
- },
- "success" : function(data) {
- justep.Util.hint("支付成功!");
- orderData.refreshData();
- }
- });
- }
- }).fail(function(code) {
- justep.Util.hint("支付遇到问题!");
- });
- }
- };
复制代码
红色圈起这部分有时候成功支付后会没有执行进去,但是大多数都是可以执行进去的,不知道我的这个写法有没有什么问题?
|
|