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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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. if (state.isPay == "1") {
  106. my.navigateToMiniProgram({
  107. appId: '2021004102619032', // 16 位
  108. path: `/subpackage/after-sale/empty?qdOrderNo=${state.qdOrderNo}&type=3&orderId=${state.orderId}&isPay=2`,
  109. query: {
  110. a: 'foo',
  111. b: 'bar',
  112. },
  113. extraData: {
  114. x: {
  115. y: 'z',
  116. },
  117. },
  118. success: function (res) {
  119. console.log(res);
  120. },
  121. fail: function (err) {
  122. console.log(err);
  123. }
  124. });
  125. }
  126. })
  127. },
  128. fail: res => {
  129. console.log("支付失败", res);
  130. },
  131. });
  132. });
  133. });
  134. },
  135. fail: err => {
  136. console.log('my.getAuthCode 调用失败', err)
  137. }
  138. });
  139. }
  140. </script>
  141. <style lang="scss" scoped>
  142. .action {
  143. margin-top: 40rpx;
  144. padding-left: 20rpx;
  145. padding-right: 20rpx;
  146. padding-bottom: 30rpx;
  147. .button {
  148. height: 80rpx;
  149. background: linear-gradient(-90deg, #43a1e0 0%, #13e7c1 100%);
  150. border-radius: 40rpx;
  151. font-size: 32rpx;
  152. font-weight: 400;
  153. color: #ffffff;
  154. line-height: 80rpx;
  155. }
  156. }
  157. .title {
  158. text-align: center;
  159. margin-top: 15rpx;
  160. font-size: 36rpx;
  161. font-family: Microsoft YaHei;
  162. font-weight: 400;
  163. color: #333333;
  164. line-height: 36rpx;
  165. }
  166. .value {
  167. padding: 0rpx 60rpx;
  168. }
  169. .content_1 {
  170. margin-top: 60rpx;
  171. font-size: 30rpx;
  172. font-family: Microsoft YaHei;
  173. font-weight: 400;
  174. color: #666666;
  175. line-height: 58rpx;
  176. }
  177. .content_2 {
  178. margin-top: 50rpx;
  179. font-size: 30rpx;
  180. font-family: Microsoft YaHei;
  181. font-weight: 400;
  182. color: #666666;
  183. line-height: 58rpx;
  184. }
  185. .content_3 {
  186. margin-top: 50rpx;
  187. font-size: 30rpx;
  188. font-family: Microsoft YaHei;
  189. font-weight: 400;
  190. color: #ff0000;
  191. line-height: 58rpx;
  192. }
  193. </style>