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

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