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.1KB

1 year ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. <template>
  2. <image
  3. style="
  4. margin-top: 20rpx;
  5. width: 100%;
  6. height: 240rpx;
  7. background-color: #eeeeee;
  8. "
  9. :src="`${$imgUrl}applyCard/car-service.png`"
  10. ></image>
  11. <view class="title"> 支付宝支付 </view>
  12. <view class="value">
  13. </view>
  14. <view class="action">
  15. <button type="default" class="button" @click="savaHandle()">
  16. 确认支付
  17. </button>
  18. <!-- <button type="default" class="button" @click="addInterestsList()">
  19. 加购权益
  20. </button> -->
  21. </view>
  22. </template>
  23. <script setup lang="ts">
  24. import { onLoad, onShow } from "@dcloudio/uni-app";
  25. import { reactive } from "vue";
  26. import { etcQYAction } from "@/utils/network/api.js";
  27. import { request } from "@/utils/network/request.js";
  28. import { stringToJson } from "@/utils/network/encryption";
  29. import { fileURL } from "@/datas/fileURL.js";
  30. import navBar from "@/components/nav-bar/nav-bar2.vue";
  31. import navBgCar from "./components/nav-bg-car4";
  32. import { setItem,StorageKeys } from "@/utils/storage";
  33. import { msg, confirm, getOrderStatusName } from "@/utils/utils";
  34. import {
  35. checkOrderStatus,
  36. orderPay,
  37. wechatAppID,
  38. wechatPayConfigId,
  39. wechatSecret,
  40. aliPayConfigId,
  41. obtainUserId,
  42. } from "@/utils/network/api";
  43. const imgURL = `${fileURL}image/`;
  44. const state = reactive({
  45. openid: "",
  46. orderId: "",
  47. id: "",
  48. clientFee: "",
  49. code:""
  50. });
  51. onLoad((option: any) => {
  52. state.orderId = option.orderId;
  53. setItem('accessToken', option.token);
  54. setItem(StorageKeys.Token, option.token);
  55. setItem('openId', option.openId);
  56. });
  57. const savaHandle = () => {
  58. my.getAuthCode({
  59. scopes: 'auth_user',
  60. success: res => {
  61. const optionsUser = {
  62. type: 2,
  63. data: {
  64. payConfigId: aliPayConfigId,
  65. code: res.authCode
  66. },
  67. method: "POST",
  68. showLoading: true,
  69. };
  70. console.log('支付宝用户编号请求:', optionsUser)
  71. request(obtainUserId, optionsUser).then((res) => {
  72. console.log('支付宝用户编号返回:', res)
  73. const data = stringToJson(res.bizContent);
  74. const optionsali = {
  75. type: 2,
  76. data: {
  77. openid: data.openId,
  78. orderId: state.orderId,
  79. payConfigId: aliPayConfigId,
  80. },
  81. method: "POST",
  82. showLoading: true,
  83. };
  84. console.log('支付下单请求:', optionsali)
  85. request(orderPay, optionsali).then((res) => {
  86. console.log('支付下单返回:', res)
  87. const data = stringToJson(res.bizContent);
  88. my.tradePay({
  89. // 调用统一收单交易创建接口(alipay.trade.create),获得返回字段支付宝交易号 trade_no
  90. tradeNO: data.prepayId,
  91. success: res => {
  92. console.log("支付成功", res);
  93. const optionsaliquery = {
  94. type: 2,
  95. data: {
  96. orderId: state.orderId,
  97. },
  98. method: "POST",
  99. showLoading: true,
  100. };
  101. request(checkOrderStatus, optionsaliquery).then((res) => {
  102. console.log('支付结果查询:', res)
  103. })
  104. },
  105. fail: res => {
  106. console.log("支付失败", res);
  107. },
  108. });
  109. });
  110. });
  111. },
  112. fail: err => {
  113. console.log('my.getAuthCode 调用失败', err)
  114. }
  115. });
  116. }
  117. </script>
  118. <style lang="scss" scoped>
  119. .action {
  120. margin-top: 40rpx;
  121. padding-left: 20rpx;
  122. padding-right: 20rpx;
  123. padding-bottom: 30rpx;
  124. .button {
  125. height: 80rpx;
  126. background: linear-gradient(-90deg, #43a1e0 0%, #13e7c1 100%);
  127. border-radius: 40rpx;
  128. font-size: 32rpx;
  129. font-weight: 400;
  130. color: #ffffff;
  131. line-height: 80rpx;
  132. }
  133. }
  134. .title {
  135. text-align: center;
  136. margin-top: 15rpx;
  137. font-size: 36rpx;
  138. font-family: Microsoft YaHei;
  139. font-weight: 400;
  140. color: #333333;
  141. line-height: 36rpx;
  142. }
  143. .value {
  144. padding: 0rpx 60rpx;
  145. }
  146. .content_1 {
  147. margin-top: 60rpx;
  148. font-size: 30rpx;
  149. font-family: Microsoft YaHei;
  150. font-weight: 400;
  151. color: #666666;
  152. line-height: 58rpx;
  153. }
  154. .content_2 {
  155. margin-top: 50rpx;
  156. font-size: 30rpx;
  157. font-family: Microsoft YaHei;
  158. font-weight: 400;
  159. color: #666666;
  160. line-height: 58rpx;
  161. }
  162. .content_3 {
  163. margin-top: 50rpx;
  164. font-size: 30rpx;
  165. font-family: Microsoft YaHei;
  166. font-weight: 400;
  167. color: #ff0000;
  168. line-height: 58rpx;
  169. }
  170. </style>