You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
2 lines
4.2 KiB
2 lines
4.2 KiB
"use strict";const c=require("../../common/vendor.js"),l=require("../index.js");require("../helper/index.js");const o=require("../api/pay/order.js");require("../request/index.js");class r{constructor(e,a,t){this.payment=e,this.id=t,this.orderType=a,this.payAction()}payAction(){return{WechatOfficialAccount:{wechat:()=>{this.wechatOfficialAccountPay()},alipay:()=>{this.redirectPay()},wallet:()=>{this.walletPay()},mock:()=>{this.mockPay()}},WechatMiniProgram:{wechat:()=>{this.wechatMiniProgramPay()},alipay:()=>{this.copyPayLink()},wallet:()=>{this.walletPay()},mock:()=>{this.mockPay()}},App:{wechat:()=>{this.wechatAppPay()},alipay:()=>{this.alipay()},wallet:()=>{this.walletPay()},mock:()=>{this.mockPay()}},H5:{wechat:()=>{this.wechatWapPay()},alipay:()=>{this.redirectPay()},wallet:()=>{this.walletPay()},mock:()=>{this.mockPay()}}}[l.sheep.$platform.name][this.payment]()}prepay(e){return new Promise(async(a,t)=>{let i={id:this.id,channelCode:e};if(["wx_pub","wx_lite"].includes(e)){const s=await l.sheep.$platform.useProvider("wechat").getOpenid();if(!s){this.bindWeixin();return}i.channelExtras.openid=s}o.PayOrderApi.submitOrder(i).then(s=>{s.code===0&&a(s);let n=c.index.getStorageSync("un_type_info");console.log(n,"un_type_info"),n=="套餐支付"&&(console.log("设置了"),c.index.setStorageSync("un_inteface",1)),c.index.setStorageSync("pay_type",c.index.getStorageSync("un_type_info")),s.code!==0&&s.msg.indexOf("无效的openid")>=0&&(s.msg.indexOf("无效的openid")>=0||s.msg.indexOf("下单账号与支付账号不一致")>=0)&&this.bindWeixin()})})}async wechatMiniProgramPay(){let{code:e,data:a}=await this.prepay("wx_lite");if(e!==0)return;const t=JSON.parse(a.displayContent);c.index.requestPayment({provider:"wxpay",timeStamp:t.timeStamp,nonceStr:t.nonceStr,package:t.packageValue,signType:t.signType,paySign:t.paySign,success:i=>{this.payResult("success")},fail:i=>{i.errMsg==="requestPayment:fail cancel"?l.sheep.$helper.toast("支付已手动取消"):this.payResult("fail")}})}async walletPay(){const{code:e}=await this.prepay("wallet");e===0&&this.payResult("success")}async mockPay(){const{code:e}=await this.prepay("mock");e===0&&this.payResult("success")}async copyPayLink(){let{error:e,data:a}=await this.prepay();e===0&&c.index.showModal({title:"支付宝支付",content:"复制链接到外部浏览器",confirmText:"复制链接",success:t=>{t.confirm&&l.sheep.$helper.copyText(a.pay_data)}})}async alipay(){let e=this;const{error:a,data:t}=await this.prepay();a===0&&c.index.requestPayment({provider:"alipay",orderInfo:t.pay_data,success:i=>{e.payResult("success")},fail:i=>{i.errMsg==="requestPayment:fail [paymentAlipay:62001]user cancel"?l.sheep.$helper.toast("支付已手动取消"):e.payResult("fail")}})}async wechatAppPay(){let e=this,{error:a,data:t}=await this.prepay();a===0&&c.index.requestPayment({provider:"wxpay",orderInfo:t.pay_data,success:i=>{e.payResult("success")},fail:i=>{i.errMsg!=="requestPayment:fail cancel"&&e.payResult("fail")}})}payResult(e){l.sheep.$router.redirect("/pages/pay/result",{id:this.id,orderType:this.orderType,payState:e})}bindWeixin(){c.index.showModal({title:"微信支付",content:"请先绑定微信再使用微信支付",success:function(e){e.confirm&&l.sheep.$platform.useProvider("wechat").bind()}})}}function y(p){const e=[{icon:"/static/img/shop/pay/wechat.png",title:"微信支付",value:"wechat",disabled:!1},{icon:"/static/img/shop/pay/alipay.png",title:"支付宝支付",value:"alipay",disabled:!1},{icon:"/static/img/shop/pay/wallet.png",title:"余额支付",value:"wallet",disabled:!1},{icon:"/static/img/shop/pay/apple.png",title:"Apple Pay",value:"apple",disabled:!0},{icon:"/static/img/shop/pay/wallet.png",title:"模拟支付",value:"mock",disabled:!0}],a=l.sheep.$platform.name,t=e[0];(a==="WechatOfficialAccount"&&p.includes("wx_pub")||a==="WechatMiniProgram"&&p.includes("wx_lite")||a==="App"&&p.includes("wx_app"))&&(t.disabled=!1),t.disabled=!1;const i=e[1];(a==="WechatOfficialAccount"&&p.includes("alipay_wap")||a==="WechatMiniProgram"&&p.includes("alipay_wap")||a==="App"&&p.includes("alipay_app"))&&(i.disabled=!1);const s=e[2];p.includes("wallet")&&(s.disabled=!1);const n=e[4];return p.includes("mock")&&(n.disabled=!1),e}exports.SheepPay=r;exports.getPayMethods=y;
|