pay.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. // +----------------------------------------------------------------------
  2. // | likeshop开源商城系统
  3. // +----------------------------------------------------------------------
  4. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  5. // | gitee下载:https://gitee.com/likeshop_gitee
  6. // | github下载:https://github.com/likeshop-github
  7. // | 访问官网:https://www.likeshop.cn
  8. // | 访问社区:https://home.likeshop.cn
  9. // | 访问手册:http://doc.likeshop.cn
  10. // | 微信公众号:likeshop技术社区
  11. // | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
  12. // | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
  13. // | 禁止对系统程序代码以任何目的,任何形式的再发布
  14. // | likeshop团队版权所有并拥有最终解释权
  15. // +----------------------------------------------------------------------
  16. // | author: likeshop.cn.team
  17. // +----------------------------------------------------------------------
  18. import wechath5 from './wechath5'
  19. import {
  20. currentPage,
  21. isWeixinClient
  22. } from './tools'
  23. export function wxpay(opt) {
  24. //#ifdef H5
  25. if (isWeixinClient()) {
  26. return wechath5.wxPay(opt)
  27. } else {
  28. console.log(opt)
  29. location.href = opt
  30. }
  31. // #endif
  32. //#ifndef H5
  33. return new Promise((resolve, reject) => {
  34. // #ifdef MP-WEIXIN
  35. const params = {
  36. timeStamp: opt.timeStamp,
  37. // 支付签名时间戳,注意微信jssdk中的所有使用timestamp字段均为小写。但最新版的支付后台生成签名使用的timeStamp字段名需大写其中的S字符
  38. nonceStr: opt.nonceStr,
  39. // 支付签名随机串,不长于 32 位
  40. package: opt.package,
  41. // 统一支付接口返回的prepay_id参数值,提交格式如:prepay_id=***)
  42. signType: opt.signType,
  43. // 签名方式,默认为'SHA1',使用新版支付需传入'MD5'
  44. paySign: opt.paySign,
  45. }
  46. // #endif
  47. // #ifdef APP-PLUS
  48. const params = {
  49. orderInfo: opt
  50. }
  51. // #endif
  52. console.log(params)
  53. uni.requestPayment({
  54. provider: 'wxpay',
  55. ...params,
  56. success: res => {
  57. resolve('success');
  58. },
  59. cancel: res => {
  60. resolve('fail');
  61. },
  62. fail: res => {
  63. resolve('fail');
  64. }
  65. });
  66. });
  67. // #endif
  68. }
  69. export function alipay(opt) {
  70. // uni.switchTab({
  71. // url: '/pages/index/index',
  72. // })
  73. //#ifdef H5
  74. // const div = document.createElement('div')
  75. // console.log(opt)
  76. // div.innerHTML = opt
  77. // document.body.appendChild(div)
  78. // document.forms[0].submit()
  79. return new Promise((resolve, reject) => {
  80. const params = {
  81. orderInfo: opt
  82. }
  83. uni.showModal({
  84. title: '提示',
  85. content: '复制网址到外部浏览器去支付',
  86. showCancel: false,
  87. success: function(res) {
  88. if (res.confirm) {
  89. // #ifdef H5
  90. if (!document.queryCommandSupported('copy')) {
  91. //为了兼容有些浏览器 queryCommandSupported 的判断
  92. // 不支持
  93. return false;
  94. }
  95. let textarea = document.createElement('textarea');
  96. textarea.value = params.orderInfo.data.qr_code;
  97. textarea.readOnly = 'readOnly';
  98. document.body.appendChild(textarea);
  99. textarea.select(); // 选择对象
  100. textarea.setSelectionRange(0, params.orderInfo.data.qr_code.length); //核心
  101. let result = document.execCommand('copy'); // 执行浏览器复制命令
  102. console.log(result, '123456');
  103. textarea.remove();
  104. return result;
  105. // #endif
  106. }
  107. }
  108. });
  109. // uni.requestPayment({
  110. // provider: 'alipay',
  111. // ...params,
  112. // success: res => {
  113. // resolve('success');
  114. // },
  115. // cancel: res => {
  116. // console.log(res)
  117. // resolve('fail');
  118. // },
  119. // fail: res => {
  120. // console.log(res)
  121. // resolve('fail');
  122. // }
  123. // });
  124. })
  125. // #endif
  126. // #ifdef APP-PLUS
  127. return new Promise((resolve, reject) => {
  128. const params = {
  129. orderInfo: opt
  130. }
  131. console.log(params)
  132. plus.runtime.openURL(params.orderInfo.data.qr_code);
  133. // uni.requestPayment({
  134. // provider: 'alipay',
  135. // ...params,
  136. // success: res => {
  137. // resolve('success');
  138. // },
  139. // cancel: res => {
  140. // console.log(res)
  141. // resolve('fail');
  142. // },
  143. // fail: res => {
  144. // console.log(res)
  145. // resolve('fail');
  146. // }
  147. // });
  148. })
  149. // #endif
  150. }