UNPKG

unique-pay

Version:

微信支付、支付宝支付聚合SDK,支持内置对象调用、jsSdk 调用,支持 vuejs、script 引用

2 lines 6.7 kB
!function(e){function n(r){if(t[r])return t[r].exports;var i=t[r]={i:r,l:!1,exports:{}};return e[r].call(i.exports,i,i.exports,n),i.l=!0,i.exports}var t={};n.m=e,n.c=t,n.i=function(e){return e},n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{configurable:!1,enumerable:!0,get:r})},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,n){return Object.prototype.hasOwnProperty.call(e,n)},n.p="/",n(n.s=1)}([function(e,n){function t(){throw new Error("setTimeout has not been defined")}function r(){throw new Error("clearTimeout has not been defined")}function i(e){if(l===setTimeout)return setTimeout(e,0);if((l===t||!l)&&setTimeout)return l=setTimeout,setTimeout(e,0);try{return l(e,0)}catch(n){try{return l.call(null,e,0)}catch(n){return l.call(this,e,0)}}}function o(e){if(f===clearTimeout)return clearTimeout(e);if((f===r||!f)&&clearTimeout)return f=clearTimeout,clearTimeout(e);try{return f(e)}catch(n){try{return f.call(null,e)}catch(n){return f.call(this,e)}}}function a(){y&&g&&(y=!1,g.length?p=g.concat(p):m=-1,p.length&&u())}function u(){if(!y){var e=i(a);y=!0;for(var n=p.length;n;){for(g=p,p=[];++m<n;)g&&g[m].run();m=-1,n=p.length}g=null,y=!1,o(e)}}function c(e,n){this.fun=e,this.array=n}function s(){}var l,f,d=e.exports={};!function(){try{l="function"==typeof setTimeout?setTimeout:t}catch(e){l=t}try{f="function"==typeof clearTimeout?clearTimeout:r}catch(e){f=r}}();var g,p=[],y=!1,m=-1;d.nextTick=function(e){var n=new Array(arguments.length-1);if(arguments.length>1)for(var t=1;t<arguments.length;t++)n[t-1]=arguments[t];p.push(new c(e,n)),1!==p.length||y||i(u)},c.prototype.run=function(){this.fun.apply(null,this.array)},d.title="browser",d.browser=!0,d.env={},d.argv=[],d.version="",d.versions={},d.on=s,d.addListener=s,d.once=s,d.off=s,d.removeListener=s,d.removeAllListeners=s,d.emit=s,d.prependListener=s,d.prependOnceListener=s,d.listeners=function(e){return[]},d.binding=function(e){throw new Error("process.binding is not supported")},d.cwd=function(){return"/"},d.chdir=function(e){throw new Error("process.chdir is not supported")},d.umask=function(){return 0}},function(e,n,t){(function(r){function i(e,n){if(!(e instanceof n))throw new TypeError("Cannot call a class as a function")}var o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},a=function(){function e(e,n){for(var t=0;t<n.length;t++){var r=n[t];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(n,t,r){return t&&e(n.prototype,t),r&&e(n,r),n}}(),u=function(){function e(n){i(this,e),"undefined"!=typeof $globalConfig&&$globalConfig.navigator||(window.$globalConfig={navigator:{isWechat:null!==navigator.userAgent.match(/(MicroMessenger)\/([\d\.]+)/i),isAlipay:null!==navigator.userAgent.match(/(AlipayClient)\/([\d\.]+)/i)}}),this._useSdk=!0===n||document.currentScript.hasAttribute("usesdk")&&"false"!==document.currentScript.getAttribute("usesdk"),this.initSdk()}return a(e,[{key:"initSdk",value:function(e){if(this._useSdk&&(this._wxSignatureConfig=e,$globalConfig.navigator.isWechat||$globalConfig.navigator.isAlipay)){var n=$globalConfig.navigator.isWechat?"//res.wx.qq.com/open/js/jweixin-1.2.0.js":"//a.alipayobjects.com/g/component/antbridge/1.1.4/antbridge.min.js";if(!n||""===n)return void console.error("UniquePay init fail , path : null");if(null===document.querySelector('script[src$="'+n+'"]')){var t=document.createElement("script");t.src=location.protocol+n,t.onload=function(){console.log("UniquePay init success !!! ")},t.onerror=function(){console.error("UniquePay init fail , path : ",n)};var r=document.getElementsByTagName("script")[0];r.parentNode.insertBefore(t,r)}}}},{key:"pay",value:function(e,n){return $globalConfig.navigator.isWechat?this.wechatPay(e,n):$globalConfig.navigator.isAlipay?this.aliPay(e):new Promise(function(){})}},{key:"wechatPay",value:function(e,n){var i=this;return new Promise(function(o,a){if(!e||"[object Object]"!==Object.prototype.toString.call(e))return void a({message:"唤起微信支付参数错误,参数[options]:"+JSON.stringify(e)});var u=function(e){o({code:(e.err_msg||"").split(":")[1]||"ok",message:e.errMsg||e.err_desc||""})},s=function(e){a({code:(e.err_msg||"").split(":")[1]||"fail",message:e.errMsg||e.err_desc||"支付失败"})};if(i._useSdk){var l=function(){e.success=u,e.cancel=function(e){a({code:(e.err_msg||"").split(":")[1]||"cancel",message:e.errMsg||e.err_desc||"支付取消"})},e.fail=s,wx.chooseWXPay(e)};n=n||i._wxSignatureConfig,!0!==i.signature&&n?(n.debug=n.debug||void 0!==r&&"production"!==(t.i({NODE_ENV:"production"})||{}).NODE_ENV,n.jsApiList=["checkJsApi","chooseWXPay"],wx.config(n),wx.ready(function(){i.signature=!0,l()}),wx.error(function(e){i.signature=!1,a({code:"fail",message:e.errMsg||e.err_desc||"jsapi配置失败"})})):l()}else c().then(function(n){n.invoke("getBrandWCPayRequest",e,function(e){"get_brand_wcpay_request:ok"===e.err_msg?u(e):s(e)})})})}},{key:"aliPay",value:function(e){var n=this;return new Promise(function(t,r){if(!e||"[object Object]"!==Object.prototype.toString.call(e))return void r({message:"唤起支付宝参数错误,参数[options]:"+JSON.stringify(e)});var i=function(e){switch(e.code=e.resultCode,e.resultCode){case"9000":t(e);break;case"8000":case"6004":e.message="支付处理中,请稍后在您的订单中查看",r(e);break;case"6001":case"99":break;default:e.message="支付异常,请关闭页面后重试",r(e)}};n._useSdk?ap.tradePay(e,i):c().then(function(n){n.call("tradePay",e,i)})})}}]),e}(),c=function(){return new Promise(function(e,n){$globalConfig.navigator.isWechat?"undefined"==typeof WeixinJSBridge?document.addEventListener?document.addEventListener("WeixinJSBridgeReady",function(){return e(WeixinJSBridge)},!1):document.attachEvent&&(document.attachEvent("WeixinJSBridgeReady",function(){return e(WeixinJSBridge)}),document.attachEvent("onWeixinJSBridgeReady",function(){return e(WeixinJSBridge)})):e(WeixinJSBridge):$globalConfig.navigator.isAlipay&&(window.AlipayJSBridge?e(window.AlipayJSBridge):document.addEventListener("AlipayJSBridgeReady",function(){return e(window.AlipayJSBridge)},!1))})},s=function e(n){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};e.installed||(n.$uniquePay=n.prototype.$uniquePay=new u(t.useSdk))};"undefined"!=typeof window&&window.Vue&&window.Vue.use(s),"object"===o(n)&&void 0!==e?e.exports=s:window.UniquePay=new u}).call(n,t(0))}]); //# sourceMappingURL=unique-pay.min.js.map