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 4.5KB

1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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. });
  49. onLoad((option : any) => {
  50. state.orderId = option.orderId;
  51. state.qdOrderNo = option.qdOrderNo;
  52. setItem('accessToken', option.token);
  53. setItem(StorageKeys.Token, option.token);
  54. setItem('openId', option.openId);
  55. });
  56. const savaHandle = () => {
  57. my.getAuthCode({
  58. scopes: 'auth_user',
  59. success: res => {
  60. const optionsUser = {
  61. type: 2,
  62. data: {
  63. payConfigId: aliPayConfigId,
  64. code: res.authCode
  65. },
  66. method: "POST",
  67. showLoading: true,
  68. };
  69. console.log('支付宝用户编号请求:', optionsUser)
  70. request(obtainUserId, optionsUser).then((res) => {
  71. console.log('支付宝用户编号返回:', res)
  72. const data = stringToJson(res.bizContent);
  73. const optionsali = {
  74. type: 2,
  75. data: {
  76. openid: data.openId,
  77. orderId: state.orderId,
  78. payConfigId: aliPayConfigId,
  79. },
  80. method: "POST",
  81. showLoading: true,
  82. };
  83. console.log('支付下单请求:', optionsali)
  84. request(orderPay, optionsali).then((res) => {
  85. console.log('支付下单返回:', res)
  86. const data = stringToJson(res.bizContent);
  87. my.tradePay({
  88. // 调用统一收单交易创建接口(alipay.trade.create),获得返回字段支付宝交易号 trade_no
  89. tradeNO: data.prepayId,
  90. success: res => {
  91. console.log("支付成功", res);
  92. const optionsaliquery = {
  93. type: 2,
  94. data: {
  95. orderId: state.orderId,
  96. },
  97. method: "POST",
  98. showLoading: true,
  99. };
  100. request(checkOrderStatus, optionsaliquery).then((res) => {
  101. console.log('支付结果查询:', res)
  102. // 支付完成跳转到h5
  103. const param = `https://qtzl.etcjz.cn/order/#/pages/payment/signAContract?qdOrderNo=${state.qdOrderNo}&type=3`
  104. const params = encodeURIComponent(JSON.stringify(param))
  105. uni.navigateTo({
  106. url: `/subpackage/personal-center/webview?url=` + params
  107. })
  108. })
  109. },
  110. fail: res => {
  111. console.log("支付失败", res);
  112. },
  113. });
  114. });
  115. });
  116. },
  117. fail: err => {
  118. console.log('my.getAuthCode 调用失败', err)
  119. }
  120. });
  121. }
  122. </script>
  123. <style lang="scss" scoped>
  124. .action {
  125. margin-top: 40rpx;
  126. padding-left: 20rpx;
  127. padding-right: 20rpx;
  128. padding-bottom: 30rpx;
  129. .button {
  130. height: 80rpx;
  131. background: linear-gradient(-90deg, #43a1e0 0%, #13e7c1 100%);
  132. border-radius: 40rpx;
  133. font-size: 32rpx;
  134. font-weight: 400;
  135. color: #ffffff;
  136. line-height: 80rpx;
  137. }
  138. }
  139. .title {
  140. text-align: center;
  141. margin-top: 15rpx;
  142. font-size: 36rpx;
  143. font-family: Microsoft YaHei;
  144. font-weight: 400;
  145. color: #333333;
  146. line-height: 36rpx;
  147. }
  148. .value {
  149. padding: 0rpx 60rpx;
  150. }
  151. .content_1 {
  152. margin-top: 60rpx;
  153. font-size: 30rpx;
  154. font-family: Microsoft YaHei;
  155. font-weight: 400;
  156. color: #666666;
  157. line-height: 58rpx;
  158. }
  159. .content_2 {
  160. margin-top: 50rpx;
  161. font-size: 30rpx;
  162. font-family: Microsoft YaHei;
  163. font-weight: 400;
  164. color: #666666;
  165. line-height: 58rpx;
  166. }
  167. .content_3 {
  168. margin-top: 50rpx;
  169. font-size: 30rpx;
  170. font-family: Microsoft YaHei;
  171. font-weight: 400;
  172. color: #ff0000;
  173. line-height: 58rpx;
  174. }
  175. </style>