index.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. <template>
  2. <view class="body">
  3. <image src="/static/czd/loading.gif" mode=""></image>
  4. <view>支付中</view>
  5. </view>
  6. </template>
  7. <script>
  8. const module = uni.requireNativePlugin('SandPayTypeModule');
  9. const dcHMPLib = uni.requireNativePlugin("HMPTLib-HMPLibModule")
  10. export default {
  11. data() {
  12. return {
  13. param: {},
  14. orderNo: null,
  15. }
  16. },
  17. onLoad(options) {
  18. const uaAppend = 'sandsdkpayios'
  19. plus.navigator.setUserAgent(plus.navigator.getUserAgent() + ' ' + uaAppend)
  20. if (options.orderNo) {
  21. this.param.orderNo = options.orderNo;
  22. this.payCreate()
  23. }
  24. },
  25. onShow() {
  26. // if(this.orderNo&&this.$u.os()=='ios'){
  27. this.getUrlType(this.orderNo)
  28. // }
  29. },
  30. methods: {
  31. getUrlType(orderNo) {
  32. this.$yghttp.post('/sand/order/getRedirectMode', {
  33. orderNo: orderNo
  34. }).then(res => {
  35. if (res.data.jumpType == 1) {
  36. uni.redirectTo({
  37. url: res.data.path+'?pagTag=1'
  38. });
  39. } else if (res.data.jumpType == 2) {
  40. uni.redirectTo({
  41. url: "/pages/web-view/Apps?path=" + res.data.path
  42. })
  43. }
  44. })
  45. },
  46. payCreate(type) {
  47. let platform = uni.getSystemInfoSync().platform;
  48. this.$yghttp.post("/sand/order/pay/create", this.param).then(res => {
  49. this.orderNo = this.param.orderNo;
  50. if (platform == 'ios') {
  51. this.allpayMethod(res.data)
  52. } else if (platform == 'android') {
  53. this.myClick(res.data)
  54. }
  55. }).catch(e => {
  56. console.log(e)
  57. })
  58. },
  59. // 安卓
  60. myClick(url) {
  61. // this.startLoading("请求中..")
  62. module.cashierPay(url, ret => {
  63. let data = JSON.parse(ret.tokenId)
  64. if (ret.funcCode === '01010005') {
  65. this.wxPay(data.tokenId)
  66. } else {
  67. this.endLoading()
  68. if (ret.funcCode) {
  69. console.log("功能编码:" + ret.funcCode)
  70. }
  71. if (ret.resultCode) {
  72. console.log("支付结果:" + ret.resultCode)
  73. } else {
  74. console.log("需调用服务端接口查询支付结果")
  75. }
  76. if (ret.failReason) {
  77. console.log("错误信息:" + ret.failReason)
  78. this.getUrlType(this.orderNo)
  79. }
  80. if (ret.ex) {
  81. console.log("异常信息:" + ret.ex);
  82. }
  83. }
  84. })
  85. },
  86. wxPay(tokenId) {
  87. plus.share.getServices(shareList => {
  88. let sweixin = shareList.find(val => val.id == 'weixin')
  89. if (sweixin) {
  90. sweixin.launchMiniProgram({
  91. id: 'gh_914ccc860aa5', //小程序原始id
  92. path: 'pages/zf/index?token_id=' + tokenId + '&funcCode=01010005',
  93. type: 0 // 正式版:0、开发版:1、体验版:2
  94. })
  95. this.endLoading()
  96. } else {
  97. uni.showToast({
  98. icon: 'none',
  99. title: "未安装微信,无法打开对应小程序"
  100. })
  101. }
  102. }, e => {
  103. uni.showToast({
  104. icon: 'none',
  105. title: "获取微信服务列表失败:" + JSON.stringify(e)
  106. })
  107. })
  108. },
  109. // ios
  110. allpayMethod(url) {
  111. // console.log("打印SDK方法", dcHMPLib.sandHMPCashierPayMethod)
  112. dcHMPLib.sandHMPCashierPayMethod(
  113. url,
  114. (ret) => {
  115. console.log("打印SDK返回的json数据" + JSON.stringify(ret))
  116. // 微信sdk吊起
  117. if (ret.status == "success" && ret.funcCode == "01010005") {
  118. // {"status":"success","subAppId":"wx899fd5","miniProgramType":"2","pathUrl":"pages/zf/index?","tokenId":"202308027092435608865476608","funcCode":"02010005","ghOriId":"gh_8f69bbed2867"}
  119. this.pullupWxSdkWith(ret.tokenId, ret.funcCode, ret.ghOriId, ret.miniProgramType);
  120. } else {
  121. this.getUrlType(this.orderNo)
  122. }
  123. })
  124. },
  125. pullupWxSdkWith(tokenId, funcCode, originalId, miniProgramType) {
  126. // 参考微信使用吊起部分代码 /* 使用微信的uniapp提供的SDK吊起 微信小程序支付 使用杉德sdk传出的tokenid 和小程序的原始id */
  127. if (plus.runtime.isApplicationExist({
  128. pname: 'com.tencent.mm',
  129. action: 'weixin://'
  130. })) {
  131. console.log("微信应用已安装");
  132. // 去配置完整的通用链接 然后在吊起 TO DO: - - - - = = = - - = - = -
  133. plus.share.getServices(function(shareList) {
  134. let sweixin = shareList.find(val => val.id == 'weixin')
  135. if (sweixin) {
  136. console.log("weixin吊起小程序");
  137. sweixin.launchMiniProgram({
  138. id: originalId, //小程序原始id
  139. path: 'pages/zf/index?token_id=' + tokenId + "&funcCode=" + funcCode,
  140. type: miniProgramType // 0表示正式版本的小程序 2表示体验版
  141. })
  142. }
  143. }, function(res) {
  144. console.log(JSON.stringify(res));
  145. uni.showToast({
  146. icon: 'none',
  147. title: "获取微信服务列表失败:" + JSON.stringify(e)
  148. })
  149. });
  150. } else {
  151. console.log("微信应用未安装");
  152. uni.showToast({
  153. icon: 'none',
  154. title: "未安装微信,无法打开对应小程序"
  155. })
  156. }
  157. },
  158. startLoading(message) {
  159. uni.showLoading({
  160. title: message
  161. })
  162. },
  163. endLoading() {
  164. uni.hideLoading()
  165. }
  166. }
  167. }
  168. </script>
  169. <style lang="scss" scoped>
  170. .body {
  171. text-align: center;
  172. padding-top: 300rpx;
  173. color: #303133;
  174. image {
  175. width: 200rpx;
  176. height: 200rpx;
  177. }
  178. }
  179. </style>