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.

payment.vue 5.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. <template>
  2. <image style="
  3. margin-top: 20rpx;
  4. width: 100%;
  5. height: 240rpx;
  6. background-color: #eeeeee;
  7. " :src="`${$imgUrl}applyCard/car-service.png`"></image>
  8. <view class="title"> 支付宝支付 </view>
  9. <view class="value">
  10. </view>
  11. <view class="action">
  12. <button type="default" class="button" @click="savaHandle()">
  13. 确认支付
  14. </button>
  15. <!-- <button type="default" class="button" @click="addInterestsList()">
  16. 加购权益
  17. </button> -->
  18. </view>
  19. </template>
  20. <script setup lang="ts">
  21. import { onLoad, onShow } from "@dcloudio/uni-app";
  22. import { reactive } from "vue";
  23. import { etcQYAction } from "@/utils/network/api.js";
  24. import { request } from "@/utils/network/request.js";
  25. import { stringToJson } from "@/utils/network/encryption";
  26. import { fileURL } from "@/datas/fileURL.js";
  27. import navBar from "@/components/nav-bar/nav-bar2.vue";
  28. import navBgCar from "./components/nav-bg-car4";
  29. import { setItem, StorageKeys } from "@/utils/storage";
  30. import { msg, confirm, getOrderStatusName } from "@/utils/utils";
  31. import {
  32. checkOrderStatus,
  33. orderPay,
  34. wechatAppID,
  35. wechatPayConfigId,
  36. wechatSecret,
  37. aliPayConfigId,
  38. obtainUserId,
  39. } from "@/utils/network/api";
  40. const imgURL = `${fileURL}image/`;
  41. const state = reactive({
  42. openid: "",
  43. orderId: "",
  44. id: "",
  45. clientFee: "",
  46. code: "",
  47. qdOrderNo: "", //渠道订单编号
  48. isPay: "",
  49. });
  50. onLoad((option : any) => {
  51. console.log("option11111", option)
  52. state.orderId = option.orderId;
  53. state.qdOrderNo = option.qdOrderNo;
  54. setItem('accessToken', option.token);
  55. setItem(StorageKeys.Token, option.token);
  56. setItem('openId', option.openId);
  57. state.isPay = option.isPay;
  58. });
  59. const savaHandle = () => {
  60. my.getAuthCode({
  61. scopes: 'auth_user',
  62. success: res => {
  63. const optionsUser = {
  64. type: 2,
  65. data: {
  66. payConfigId: aliPayConfigId,
  67. code: res.authCode
  68. },
  69. method: "POST",
  70. showLoading: true,
  71. };
  72. console.log('支付宝用户编号请求:', optionsUser)
  73. request(obtainUserId, optionsUser).then((res) => {
  74. console.log('支付宝用户编号返回:', res)
  75. const data = stringToJson(res.bizContent);
  76. const optionsali = {
  77. type: 2,
  78. data: {
  79. openid: data.openId,
  80. orderId: state.orderId,
  81. payConfigId: aliPayConfigId,
  82. },
  83. method: "POST",
  84. showLoading: true,
  85. };
  86. console.log('支付下单请求:', optionsali)
  87. request(orderPay, optionsali).then((res) => {
  88. console.log('支付下单返回:', res)
  89. const data = stringToJson(res.bizContent);
  90. my.tradePay({
  91. // 调用统一收单交易创建接口(alipay.trade.create),获得返回字段支付宝交易号 trade_no
  92. tradeNO: data.prepayId,
  93. success: res => {
  94. console.log("支付成功", res);
  95. const optionsaliquery = {
  96. type: 2,
  97. data: {
  98. orderId: state.orderId,
  99. },
  100. method: "POST",
  101. showLoading: true,
  102. };
  103. request(checkOrderStatus, optionsaliquery).then((res) => {
  104. console.log('支付结果查询:', res)
  105. // 支付完成跳转到h5
  106. // const param = `https://qtzl.etcjz.cn/order/#/pages/payment/payment?qdOrderNo=${state.qdOrderNo}&type=3`
  107. // const params = encodeURIComponent(JSON.stringify(param))
  108. // console.log('支付结果查询params', params)
  109. // uni.navigateTo({
  110. // url: `/subpackage/personal-center/webview?url=` + params
  111. // })
  112. if (state.isPay == "1") {
  113. my.navigateToMiniProgram({
  114. appId: '2021004102619032', // 16 位
  115. path: `/subpackage/after-sale/empty?qdOrderNo=${state.qdOrderNo}&type=3&orderId=${state.orderId}isPay=2`,
  116. query: {
  117. a: 'foo',
  118. b: 'bar',
  119. },
  120. extraData: {
  121. x: {
  122. y: 'z',
  123. },
  124. },
  125. success: function (res) {
  126. console.log(res);
  127. },
  128. fail: function (err) {
  129. console.log(err);
  130. }
  131. });
  132. }
  133. // my.navigateBackMiniProgram({
  134. // extraData: {
  135. // 'qdOrderNo': state.qdOrderNo,
  136. // 'type': 3
  137. // },
  138. // success: (res) => {
  139. // console.log(res)
  140. // },
  141. // fail: (err) => {
  142. // console.log(err)
  143. // }
  144. // });
  145. })
  146. },
  147. fail: res => {
  148. console.log("支付失败", res);
  149. },
  150. });
  151. });
  152. });
  153. },
  154. fail: err => {
  155. console.log('my.getAuthCode 调用失败', err)
  156. }
  157. });
  158. }
  159. </script>
  160. <style lang="scss" scoped>
  161. .action {
  162. margin-top: 40rpx;
  163. padding-left: 20rpx;
  164. padding-right: 20rpx;
  165. padding-bottom: 30rpx;
  166. .button {
  167. height: 80rpx;
  168. background: linear-gradient(-90deg, #43a1e0 0%, #13e7c1 100%);
  169. border-radius: 40rpx;
  170. font-size: 32rpx;
  171. font-weight: 400;
  172. color: #ffffff;
  173. line-height: 80rpx;
  174. }
  175. }
  176. .title {
  177. text-align: center;
  178. margin-top: 15rpx;
  179. font-size: 36rpx;
  180. font-family: Microsoft YaHei;
  181. font-weight: 400;
  182. color: #333333;
  183. line-height: 36rpx;
  184. }
  185. .value {
  186. padding: 0rpx 60rpx;
  187. }
  188. .content_1 {
  189. margin-top: 60rpx;
  190. font-size: 30rpx;
  191. font-family: Microsoft YaHei;
  192. font-weight: 400;
  193. color: #666666;
  194. line-height: 58rpx;
  195. }
  196. .content_2 {
  197. margin-top: 50rpx;
  198. font-size: 30rpx;
  199. font-family: Microsoft YaHei;
  200. font-weight: 400;
  201. color: #666666;
  202. line-height: 58rpx;
  203. }
  204. .content_3 {
  205. margin-top: 50rpx;
  206. font-size: 30rpx;
  207. font-family: Microsoft YaHei;
  208. font-weight: 400;
  209. color: #ff0000;
  210. line-height: 58rpx;
  211. }
  212. </style>