選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

recharge-weixin.vue 25KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030
  1. <template>
  2. <view class="wrapper">
  3. <view class="account">
  4. <image :src="`${$imgUrl}common/bg-recharge.png`" class="head-bg" mode="aspectFill"></image>
  5. <view class="account-text">
  6. <view class="balance">
  7. <text class="balance-tit">账户余额</text>
  8. <text class="balance-val">{{card.money/100}}元</text>
  9. </view>
  10. <view class="right-box">
  11. <view class="no">账户编号:000100</view>
  12. <view class="btn btn-record" @click="goRecord()">账户充值记录</view>
  13. </view>
  14. </view>
  15. </view>
  16. <view class="input-box">
  17. <input v-model="state.money" placeholder="请输入金额" class="input" />
  18. <view class="tips">最低充值金额不小于10元</view>
  19. </view>
  20. <view class="tabs">
  21. <!-- <view class="tab-tit as-gravity-center-start">充值方式
  22. <u-input @click="state.transWayTypeShow = true" inputAlign="center" v-model="state.transWayName"
  23. type="select" />
  24. </view> -->
  25. <view class="tab-tit">在线充值</view>
  26. <view class="tab">
  27. <view v-for="(item,index) in state.moneryArray" @click="tableIndexAction(index)" :key="index"
  28. :class="{'item':state.moneryArray,'active':state.tableIndex===index}">{{item.name}}</view>
  29. </view>
  30. </view>
  31. <view class="btn btn-primary" @click="rechargeAction">立即充值</view>
  32. </view>
  33. <u-select v-model="state.transWayTypeShow" :list="state.transWayTypeList" @confirm="selectConfirm"></u-select>
  34. </template>
  35. <script setup lang="ts">
  36. import {
  37. stringToJson
  38. } from "@/utils/network/encryption";
  39. import {
  40. onLoad,
  41. onShow
  42. } from "@dcloudio/uni-app";
  43. import {
  44. quanCheck,
  45. quanApply,
  46. quanXf,
  47. cardCzPayResultCheck,
  48. cardCzApply,
  49. cardCzPay,
  50. cardCzPayResult,
  51. cardCzXFCheck,
  52. quanConfirm,
  53. wechatAppID,
  54. wechatPayConfigId,
  55. wechatSecret,
  56. aliPayConfigId,
  57. obtainUserId,
  58. getOpenidApi
  59. } from "@/utils/network/api.js";
  60. import {
  61. request
  62. } from "@/utils/network/request.js";
  63. import {
  64. reactive
  65. } from "vue";
  66. import {
  67. navTo
  68. } from "@/utils/utils"
  69. import {
  70. msg
  71. } from "@/utils/utils";
  72. import {
  73. getItem,
  74. StorageKeys,
  75. setItem
  76. } from "@/utils/storage";
  77. const datas = require("../../static/etcUtil/datas.js");
  78. const bluetoothUtil = require("../../static/etcUtil/index.js");
  79. const cmd = require("../../static/etcUtil/cmdConfig.js");
  80. const tools = require("../../static/etcUtil/tools.js");
  81. const NFCAPI = require('../../static/nfc/NFCAPI.js');
  82. const state = reactive({
  83. transWayTypeShow: false,
  84. transWayTypeList: [{
  85. label: "蓝牙",
  86. value: "blu",
  87. }, {
  88. label: "NFC",
  89. value: "nfc",
  90. }
  91. ],
  92. isShowBlue: false,
  93. moneryArray: [{
  94. name: '50元',
  95. value: 50
  96. }, {
  97. name: '100元',
  98. value: 100
  99. }, {
  100. name: '200元',
  101. value: 200
  102. }, {
  103. name: '300元',
  104. value: 300
  105. }, {
  106. name: '500元',
  107. value: 500
  108. }, {
  109. name: '1000元',
  110. value: 1000
  111. }],
  112. tableIndex: 0,
  113. openid: "",
  114. connectSuccess: undefined,
  115. fee: 5000,
  116. money: 50,
  117. orderNum: "",
  118. transWayName: "蓝牙",
  119. transWay: "blu", //“blu”为蓝牙充值方式、“nfc”为NFC充值方式
  120. cardId: "", //卡号 需要传参
  121. mockpreBalance: 2000, //fix:模拟余额 目前没有检测状态接口,第一次会模拟圈层检测来检测状态
  122. show: false,
  123. items: [{
  124. value: '0',
  125. name: '微信',
  126. checked: 'true'
  127. },
  128. {
  129. value: '1',
  130. name: '对公账户'
  131. }
  132. ],
  133. current: 0
  134. });
  135. const selectConfirm = (item : any) => {
  136. state.transWayName = item[0].label
  137. state.transWay = item[0].value
  138. };
  139. //读卡信息
  140. const card : any = reactive({
  141. cardId: "",
  142. netId: "",
  143. cardType: "",
  144. startTime: "",
  145. endTime: "",
  146. userName: "",
  147. idNum: "",
  148. vehiclePlate: "",
  149. vehiclePlateColor: "",
  150. color: "",
  151. version: "",
  152. type: "",
  153. favourable: "",
  154. money: 0,
  155. v_userType: "",
  156. });
  157. onLoad((option) => {
  158. /*获取openId 用途:(用户支付)*/
  159. // #ifdef MP-WEIXIN
  160. getOpenID();/*传参*/
  161. // #endif
  162. console.log("开始option", option)
  163. state.transWay = option.transWay == 'nfc' ? "nfc" : "blu"
  164. // state.cardId = option.cardId;
  165. state.connectSuccess = option.connectSuccess;
  166. state.orderNum = getItem("orderNum");
  167. // 金额回填,本来是好的,但是他跳转了,跳转过来就得刷新页面,所以就是默认的5000
  168. if (option.fee) {
  169. state.fee = option.fee
  170. state.money = option.fee / 100
  171. } else {
  172. state.fee = state.money * 100; //元换成分
  173. }
  174. console.log("state.fee", option, state.fee)
  175. //跳转过来走圈存流程
  176. // connectSuccess 2 从选择方式进来去圈存检测 1 只读卡
  177. if (state.connectSuccess === "1") {
  178. /*读卡*/
  179. getCardId(1);
  180. } else {
  181. //进行真实圈层检测
  182. quanCheckActionTrue().then((val : any) => {
  183. console.log("圈层检测val", val)
  184. //如果 圈层检测正常
  185. if (val.chargeStatus === 1) {
  186. console.log(`进行充值检测`);
  187. //充值检测
  188. czCheckAction().then((checkResult : any) => {
  189. //判断订单逻辑如果有订单充值 则直接拿到订单去链接蓝牙
  190. if (checkResult.orders && checkResult.orders.length > 0) {
  191. //拿到订单,存起来
  192. state.orderNum = checkResult.orders[0].orderNum;
  193. setItem("orderNum", state.orderNum);
  194. // 检测用户是否存在有半条流水
  195. } else {
  196. console.log('没有可修复的流水')
  197. }
  198. });
  199. } else {
  200. // 检测用户是否存在有半条流水
  201. }
  202. });
  203. }
  204. });
  205. function radioChange(evt) {
  206. console.log('输出内容', evt)
  207. state.transWay = evt.detail.value; //“blu”为蓝牙充值方式、“nfc”为NFC充值方式
  208. }
  209. function go(money) {
  210. let content = ""
  211. if (money) {
  212. state.fee = money * 100
  213. content = '待消费订单' + money + '元'
  214. } else {
  215. content = '待消费订单'
  216. }
  217. uni.showModal({
  218. title: '提示',
  219. content: content,
  220. showCancel: false,
  221. success: (res) => {
  222. if (res.confirm) {
  223. //走蓝牙进行修复
  224. quanCheckActionTrue().then((val : any) => {
  225. console.log("圈层检测val", val)
  226. //如果 圈层检测正常
  227. if (val.chargeStatus === 1) {
  228. console.log(`进行充值检测`);
  229. czCheckAction().then((checkResult : any) => {
  230. //判断订单逻辑如果有订单充值 则直接拿到订单去链接蓝牙
  231. if (checkResult.orders && checkResult.orders.length > 0) {
  232. //拿到订单,存起来
  233. state.orderNum = checkResult.orders[0].orderNum;
  234. setItem("orderNum", state.orderNum);
  235. // 检测用户是否存在有半条流水
  236. getCardId()
  237. } else {
  238. console.log('没有可修复的流水')
  239. }
  240. });
  241. } else {
  242. // 检测用户是否存在有半条流水
  243. // let fixFee = val.fixFee / 100
  244. // console.log("fixFee", fixFee)
  245. // go(fixFee)
  246. getCardId()
  247. }
  248. });
  249. } else if (res.cancel) {
  250. console.log('用户点击取消');
  251. }
  252. console.log("state.isShowBlue", state.isShowBlue)
  253. },
  254. fail: () => {
  255. }
  256. })
  257. }
  258. const tableIndexAction = (val : any) => {
  259. state.tableIndex = val
  260. state.money = state.moneryArray[val].value
  261. }
  262. /*点击充值按钮*/
  263. const rechargeAction = () => {
  264. state.fee = state.money * 100; //元换成分
  265. uni.showModal({
  266. title: '圈存确认',
  267. content: '您确定要充值圈存吗',
  268. success: function (res) {
  269. if (res.confirm) {
  270. /*进行圈层检测,此处检测仅为校验圈层状态来决定去哪里*/
  271. console.log("进行圈层检测");
  272. quanCheckActionTrue().then((val : any) => {
  273. console.log("圈存检测接口返回", val)
  274. //如果 圈层检测正常
  275. if (val.chargeStatus === 1) {
  276. console.log(`进行充值检测`);
  277. czCheckAction().then((checkResult : any) => {
  278. console.log("进行充值检测", checkResult)
  279. //判断订单逻辑如果有订单充值 则直接拿到订单去链接蓝牙
  280. if (checkResult.orders && checkResult.orders.length > 0) {
  281. state.fee = checkResult.orders[0]['rechargeMoney']
  282. state.money = checkResult.orders[0]['rechargeMoney'] / 100
  283. //拿到订单,存起来
  284. state.orderNum = checkResult.orders[0].orderNum;
  285. setItem("orderNum", state.orderNum);
  286. //链接蓝牙
  287. go(state.money)
  288. } else {
  289. cardCzApplyAction().then((applyResult : any) => {
  290. //拿到订单 存起来
  291. state.orderNum = applyResult.orderNum;
  292. setItem("orderNum", state.orderNum);
  293. //如果订单没有支付 走支付
  294. if (applyResult.orderStatus === "ORDER_NOT_PAY") {
  295. //走支付
  296. console.log("走支付");
  297. // #ifdef MP-WEIXIN
  298. wxPayment();
  299. // #endif
  300. // #ifdef MP-ALIPAY
  301. aliPayment()
  302. // #endif
  303. }
  304. });
  305. }
  306. });
  307. } else {
  308. //走蓝牙进行修复
  309. // 圈存检测异常,继续上次圈存 chargeStatus==2
  310. let fixFee = val.fixFee / 100
  311. console.log("fixFee", fixFee)
  312. go(fixFee)
  313. }
  314. });
  315. }
  316. }
  317. });
  318. };
  319. /*读卡*/
  320. const getCardId = (readCard: number) => {
  321. console.log("======获取卡信息======");
  322. let cmdArr = [
  323. cmd.HOME_DIRECTORY,
  324. //选择主目
  325. cmd.APPLICATION_DIRECTORY,
  326. //选择文件1001--DF01联网收费应用目录
  327. cmd.CMD_READBINARY,
  328. //15文件--卡片发行基本数据文件
  329. cmd.CMD_GETBALANCE,
  330. //钱包
  331. ];
  332. tools.showLoadingAlert("正在执行指令");
  333. transCmd(cmdArr, function (res : any) {
  334. if (readCard == 1) {
  335. // 只读卡号
  336. getCardIdReturnReadCard(res)
  337. } else {
  338. getCardIdReturn(res);
  339. }
  340. })
  341. };
  342. function getCardIdReturnReadCard(res : any) {
  343. tools.hideLoadingAlert();
  344. //10:写卡 20:写OBU
  345. let str = res[2].substring(res[2].length - 4, res[2].length);
  346. let str3 = res[3].substring(res[3].length - 4, res[3].length);
  347. if (str == "9000" || str3 == "9000") {
  348. if (res[2].length > 86 || res[3] >= 12) {
  349. state.cardId = res[2].substring(20, 40); //卡号
  350. card.cardId = res[2].substring(20, 40); //卡号
  351. card.money = parseInt(parseInt(res[3].substring(0, 8), 16), 10)
  352. console.log("======卡信息======", card, state.cardId);
  353. } else {
  354. console.error("CMD_READBINARY指令长度不符" + res[2]);
  355. tools.hideLoadingAlert();
  356. }
  357. }
  358. console.error("CMD_READBINARY指令长度不符" + res[2]);
  359. tools.hideLoadingAlert();
  360. }
  361. function getCardIdReturn(res : any) {
  362. tools.hideLoadingAlert();
  363. //10:写卡 20:写OBU
  364. let str = res[2].substring(res[2].length - 4, res[2].length);
  365. let str3 = res[3].substring(res[3].length - 4, res[3].length);
  366. if (str == "9000" || str3 == "9000") {
  367. if (res[2].length > 86 || res[3] >= 12) {
  368. state.cardId = res[2].substring(20, 40); //卡号
  369. card.cardId = res[2].substring(20, 40); //卡号
  370. card.startTime = res[2].substring(40, 48);
  371. card.endTime = res[2].substring(48, 56);
  372. card.version = res[2].substring(18, 19) >= 4 ? "4x" : "2x";
  373. card.netId = res[2].substring(20, 24);
  374. card.cardType = res[2].substring(28, 29) == 23 ? 1 : 2;
  375. card.vehiclePlateColor = parseInt(res[2].substring(82, 84), 16);
  376. (card.money = parseInt(parseInt(res[3].substring(0, 8), 16), 10)),
  377. console.log("======卡信息======", card, card.money);
  378. // if (card.cardId !== state.cardId) {
  379. // msg("设备卡信息与当前充值卡号不匹配,请核对卡号");
  380. // return;
  381. // }
  382. quanCheckActionTrue().then((val) => {
  383. checkQuanCengEvent(val);
  384. });
  385. } else {
  386. console.error("CMD_READBINARY指令长度不符" + res[2]);
  387. tools.hideLoadingAlert();
  388. }
  389. }
  390. console.error("CMD_READBINARY指令长度不符" + res[2]);
  391. tools.hideLoadingAlert();
  392. }
  393. const checkQuanCengEvent = (val : any) => {
  394. if (val.chargeStatus === 1) {
  395. let cmdArr = val.command.split(",");
  396. uni.showLoading({
  397. title: "写入中",
  398. });
  399. transCmd(cmdArr, function (res : any) {
  400. let response = res.toString();
  401. var dic = {
  402. command: val.command,
  403. cosResponse: response,
  404. };
  405. uni.hideLoading();
  406. cardCzXFCheckAction().then((xfRes) => {
  407. quanApplyAction(dic).then((value : any) => {
  408. console.log("圈层申请完后的结果");
  409. console.log(value.commandType, value);
  410. //圈存初始化验证通过 , 进行圈存
  411. if (value.commandType === 2) {
  412. uanConfirmAction(value);
  413. } else {
  414. quanApplyAction(value).then((values) => {
  415. console.log("圈层申请完后的结果");
  416. uanConfirmAction(values);
  417. });
  418. // msg("圈存初始化指令验证失败, 重新初始化");
  419. }
  420. });
  421. });
  422. });
  423. } else {
  424. let cmdArr = val.command.split(",");
  425. uni.showLoading({
  426. title: "写入中",
  427. });
  428. transCmd(cmdArr, function (res : any) {
  429. var status = res[1].substring(res[1].length - 4, res[1].length);
  430. console.log("打印状态");
  431. console.log(status);
  432. if (status === "9000") {
  433. console.log("修复指令入参");
  434. let response = res.toString();
  435. var dic = {
  436. command: val.command,
  437. cosResponse: response,
  438. rechargeId: val.rechargeId,
  439. };
  440. quanFixAction(dic).then((value : any) => {
  441. console.log(value);
  442. console.log("修复结果返回");
  443. var fixStatus = value.fixStatus;
  444. //圈存修复COS指令Response信息不足,重新进行修复初始化
  445. if (fixStatus === 3) {
  446. let xfcmdArr = value.command.split(",");
  447. bluetoothUtil.transCmd(xfcmdArr, "10", function (resValueData) {
  448. var status = resValueData[1].substring(
  449. resValueData[1].length - 4,
  450. resValueData[1].length
  451. );
  452. console.log("打印状态");
  453. console.log(status);
  454. if (status === "9000") {
  455. console.log(resValueData);
  456. var valueResponse = resValueData.toString();
  457. console.log(response);
  458. var applyDic = {
  459. command: value.command,
  460. cosResponse: valueResponse,
  461. rechargeId: value.rechargeId,
  462. };
  463. console.log("消费成功");
  464. quanApplyAction(applyDic).then((applyValue) => {
  465. uanConfirmAction(applyValue);
  466. });
  467. }
  468. });
  469. } else if (fixStatus === 2) {
  470. uanConfirmSucessAction(value).then((confirmResult) => {
  471. console.log("充值成功")
  472. getCardId(1)
  473. setTimeout(() => {
  474. msg("充值成功");
  475. navTo(`/pages/recharge/result`)
  476. }, 2000)
  477. });
  478. } else if (fixStatus === 1) {
  479. quanCheckActionTrue().then((val) => {
  480. checkQuanCengEvent(val);
  481. });
  482. }
  483. });
  484. uni.hideLoading();
  485. }
  486. });
  487. }
  488. };
  489. /*透传*/
  490. const transCmd = (cmd : any, click : any) => {
  491. if (state.transWay == 'blu') {
  492. bluetoothUtil.transCmd(cmd, "10", function (res : any) {
  493. click(res);
  494. });
  495. } else {
  496. //nfc透传
  497. NFCAPI.transCmd(cmd, function (res : any) {
  498. tools.hideLoadingAlert();
  499. if (res.code == 0) {
  500. click(res.data);
  501. } else {
  502. //透传失败返回
  503. tools.alertF(res.msg);
  504. }
  505. });
  506. }
  507. };
  508. const quanCheckActionTrue = () => {
  509. console.log("进行真实圈层检测");
  510. var data = {
  511. cardId: card.cardId,
  512. fee: state.fee,
  513. preBalance: card.money,
  514. tradeType: 14,
  515. };
  516. const options = {
  517. type: 2,
  518. data: data,
  519. method: "POST",
  520. showLoading: true,
  521. };
  522. return new Promise(async (resolve, reject) => {
  523. const res = await request(quanCheck, options);
  524. const data = stringToJson(res.bizContent);
  525. resolve(data);
  526. }).catch((error) => {
  527. reject(error);
  528. });
  529. };
  530. /*充值消费*/
  531. const cardCzXFCheckAction = () => {
  532. var data = {
  533. cardId: card.cardId, //修复初始化的指令
  534. openId: getItem(StorageKeys.OpenId), //修复初始化结果
  535. orderNum: state.orderNum, //充值流水号
  536. };
  537. const options = {
  538. type: 2,
  539. data: data,
  540. method: "POST",
  541. showLoading: true,
  542. };
  543. return new Promise(async (resolve, reject) => {
  544. const res = await request(cardCzXFCheck, options);
  545. const data = stringToJson(res.bizContent);
  546. resolve(data);
  547. }).catch((error) => {
  548. reject(error);
  549. });
  550. };
  551. /*圈存修复*/
  552. const quanFixAction = (val) => {
  553. var data = {
  554. command: val.command, //修复初始化的指令
  555. cosResponse: val.cosResponse, //修复初始化结果
  556. rechargeId: val.rechargeId, //充值流水号
  557. };
  558. const options = {
  559. type: 2,
  560. data: data,
  561. method: "POST",
  562. showLoading: true,
  563. };
  564. return new Promise(async (resolve, reject) => {
  565. const res = await request(quanXf, options);
  566. const data = stringToJson(res.bizContent);
  567. resolve(data);
  568. }).catch((error) => {
  569. reject(error);
  570. });
  571. };
  572. /*圈层申请*/
  573. const quanApplyAction = (data) => {
  574. console.log("圈层申请data====", data, data.rechargeId)
  575. var form = {
  576. cardId: card.cardId,
  577. fee: state.fee,
  578. preBalance: card.money,
  579. tradeType: 14,
  580. command: data.command,
  581. cosResponse: data.cosResponse,
  582. orderId: state.orderNum,
  583. rechargeId: data.rechargeId,
  584. openId: getItem(StorageKeys.OpenId)
  585. };
  586. const options = {
  587. type: 2,
  588. data: form,
  589. method: "POST",
  590. showLoading: true,
  591. };
  592. return new Promise(async (resolve, reject) => {
  593. const res = await request(quanApply, options);
  594. const data = stringToJson(res.bizContent);
  595. resolve(data);
  596. }).catch((error) => {
  597. reject(error);
  598. });
  599. };
  600. /*圈层确认*/
  601. const uanConfirmAction = (data : any) => {
  602. console.log("圈层确认进入");
  603. let cmdArr = data.command.split(",");
  604. console.log(cmdArr);
  605. transCmd(cmdArr, function (res : any) {
  606. console.log("圈层透传");
  607. console.log(res);
  608. var arraylenth = res.length;
  609. var status = res[arraylenth - 1].substring(
  610. res[arraylenth - 1].length - 4,
  611. res[arraylenth - 1].length
  612. );
  613. console.log("打印圈层确认指令状态");
  614. if (status === "9000") {
  615. var form = {
  616. command: data.command,
  617. cosResponse: res.toString(),
  618. rechargeId: data.rechargeId,
  619. paidAmount: state.fee,
  620. giftAmount: 0,
  621. };
  622. const options = {
  623. type: 2,
  624. data: form,
  625. method: "POST",
  626. showLoading: true,
  627. };
  628. return new Promise(async () => {
  629. const res = await request(quanConfirm, options);
  630. const data = stringToJson(res.bizContent);
  631. console.log("data充值成功", data);
  632. getCardId(1)
  633. setTimeout(() => {
  634. msg("充值成功");
  635. navTo(`/pages/recharge/result`)
  636. }, 2000)
  637. }).catch((error) => {
  638. console.log('输出内容', error)
  639. });
  640. }
  641. });
  642. };
  643. const uanConfirmSucessAction = (data) => {
  644. var form = {
  645. command: data.command,
  646. cosResponse: "9000",
  647. rechargeId: data.rechargeId,
  648. paidAmount: state.fee,
  649. giftAmount: 0,
  650. };
  651. const options = {
  652. type: 2,
  653. data: form,
  654. method: "POST",
  655. showLoading: true,
  656. };
  657. return new Promise(async (resolve, reject) => {
  658. const res = await request(quanConfirm, options);
  659. const data = stringToJson(res.bizContent);
  660. resolve(data);
  661. console.log("uanConfirmSucessAction", data)
  662. }).catch((error) => {
  663. reject(error);
  664. });
  665. };
  666. /*充值检测*/
  667. const czCheckAction = () => {
  668. var form = {
  669. cardId: state.cardId,
  670. openId: getItem(StorageKeys.OpenId),
  671. };
  672. const options = {
  673. type: 2,
  674. data: form,
  675. method: "POST",
  676. showLoading: true,
  677. };
  678. return new Promise(async (resolve, reject) => {
  679. const res = await request(cardCzPayResultCheck, options);
  680. const data = stringToJson(res.bizContent);
  681. console.log("充值检测", data)
  682. resolve(data);
  683. }).catch((error) => {
  684. reject(error);
  685. });
  686. };
  687. /*充值申请*/
  688. const cardCzApplyAction = () => {
  689. var data = {
  690. cardId: state.cardId,
  691. openId: getItem(StorageKeys.OpenId),
  692. rechargeMoney: state.fee,
  693. };
  694. const options = {
  695. type: 2,
  696. data: data,
  697. method: "POST",
  698. showLoading: true,
  699. };
  700. return new Promise(async (resolve, reject) => {
  701. const res = await request(cardCzApply, options);
  702. const data = stringToJson(res.bizContent);
  703. resolve(data);
  704. }).catch((error) => {
  705. reject(error);
  706. });
  707. };
  708. //获取微信小程序openid
  709. const getOpenID = () => {
  710. uni.login({
  711. provider: "weixin",
  712. success: function (e) {
  713. getOpenid(e.code);
  714. },
  715. fail: function () {
  716. msg("获取不到oppenId,请检查AppID和Secret是否争取");
  717. },
  718. });
  719. };
  720. const getOpenid = (code) => {
  721. const options = {
  722. type: 2,
  723. data: {
  724. "jsCode": code
  725. },
  726. method: "POST",
  727. showLoading: true,
  728. };
  729. // #ifdef MP-WEIXIN
  730. request(getOpenidApi, options).then((res) => {
  731. const result = stringToJson(res.bizContent);
  732. console.log("获取微信小程序openid", result);
  733. const openidData = stringToJson(result.data);
  734. // setItem("QYorder", result.data);
  735. state.openid = openidData.openid
  736. });
  737. // #endif
  738. }
  739. //掉起微信支付
  740. const wxPayment = () => {
  741. // #ifdef MP-WEIXIN
  742. const options = {
  743. type: 2,
  744. data: {
  745. openId: getItem(StorageKeys.OpenId),
  746. wxOpenId: state.openid,
  747. cardId: state.cardId,
  748. orderNum: state.orderNum,
  749. payConfigId: wechatPayConfigId,
  750. body: "储值卡充值",
  751. },
  752. method: "POST",
  753. showLoading: true,
  754. };
  755. request(cardCzPay, options).then((res) => {
  756. const data = stringToJson(res.bizContent);
  757. uni.requestPayment({
  758. provider: "wxpay",
  759. orderInfo: "",
  760. timeStamp: data.timestamp,
  761. nonceStr: data.noncestr,
  762. package: data.wxPackage ? data.wxPackage : "",
  763. signType: data.signType,
  764. paySign: data.sign,
  765. success: function () {
  766. //回调订单状态
  767. console.log("回调订单状态");
  768. checkOrder();
  769. },
  770. fail: function (err) {
  771. confirm(err, () => { }, "支付失败", false);
  772. },
  773. });
  774. });
  775. // #endif
  776. };
  777. //掉起支付宝支付
  778. const aliPayment = () => {
  779. // #ifdef MP-ALIPAY
  780. my.getAuthCode({
  781. scopes: 'auth_base',
  782. success: res => {
  783. const optionsUser = {
  784. type: 2,
  785. data: {
  786. payConfigId: aliPayConfigId,
  787. code: res.authCode
  788. },
  789. method: "POST",
  790. showLoading: true,
  791. };
  792. request(obtainUserId, optionsUser).then((res) => {
  793. const data = stringToJson(res.bizContent);
  794. const optionsali = {
  795. type: 2,
  796. data: {
  797. openId: getItem(StorageKeys.OpenId),
  798. wxOpenId: data.openId,
  799. cardId: state.cardId,
  800. orderNum: state.orderNum,
  801. payConfigId: "6a9a54123456578934edfre132b1234",
  802. body: "储值卡充值",
  803. },
  804. method: "POST",
  805. showLoading: true,
  806. };
  807. request(cardCzPay, optionsali).then((res) => {
  808. const data = stringToJson(res.bizContent);
  809. my.tradePay({
  810. // 调用统一收单交易创建接口(alipay.trade.create),获得返回字段支付宝交易号 trade_no
  811. tradeNO: data.tranPackage,
  812. success: res => {
  813. console.log("支付成功", res);
  814. checkOrder();
  815. },
  816. fail: res => {
  817. confirm(res, () => { }, "支付失败", false);
  818. },
  819. });
  820. });
  821. });
  822. },
  823. fail: err => {
  824. console.log('my.getAuthCode 调用失败', err)
  825. }
  826. });
  827. // #endif
  828. };
  829. //支付成功改变订单状态
  830. const checkOrder = () => {
  831. const options = {
  832. type: 2,
  833. data: {
  834. cardId: state.cardId,
  835. openId: getItem(StorageKeys.OpenId),
  836. orderNum: state.orderNum,
  837. },
  838. method: "POST",
  839. showLoading: true,
  840. };
  841. request(cardCzPayResult, options).then((res) => {
  842. const data = stringToJson(res.bizContent);
  843. if (data.tradeState === "SUCCESS") {
  844. getCardId();
  845. }
  846. console.log(data);
  847. });
  848. };
  849. const goRecord = () => {
  850. uni.navigateTo({
  851. url: `/subpackage/personal-center/consumption-record?cardId=${state.cardId}`
  852. })
  853. }
  854. </script>
  855. <style>
  856. .account {
  857. height: 224rpx;
  858. width: 690rpx;
  859. margin: 30rpx;
  860. position: relative;
  861. }
  862. .account .account-text {
  863. display: flex;
  864. justify-content: space-between;
  865. padding: 20rpx 50rpx;
  866. height: 100%;
  867. }
  868. .account .balance {
  869. display: flex;
  870. flex-direction: column;
  871. justify-content: center;
  872. align-items: flex-start;
  873. color: #ffffff;
  874. }
  875. .account .balance-tit {
  876. font-size: 26rpx;
  877. margin-bottom: 10rpx;
  878. }
  879. .account .balance-val {
  880. font-size: 56rpx;
  881. }
  882. .account .right-box {
  883. display: flex;
  884. flex-direction: column;
  885. justify-content: flex-start;
  886. align-items: flex-end;
  887. }
  888. .account .right-box .no {
  889. font-size: 26rpx;
  890. color: #ffffff;
  891. }
  892. .account .right-box .btn {
  893. font-size: 26rpx;
  894. padding: 0 20rpx;
  895. box-sizing: border-box;
  896. height: 42rpx;
  897. line-height: 42rpx;
  898. color: #28d20f;
  899. background: #ffffff;
  900. border-radius: 21rpx;
  901. display: inline-block;
  902. margin-top: 18rpx;
  903. }
  904. .account .head-bg {
  905. width: 690rpx;
  906. height: 224rpx;
  907. position: absolute;
  908. left: 0;
  909. top: 0;
  910. z-index: -99;
  911. }
  912. .input-box {
  913. display: flex;
  914. flex-direction: column;
  915. justify-content: center;
  916. align-items: center;
  917. padding: 20rpx 0;
  918. }
  919. .input-box .input {
  920. width: 430rpx;
  921. height: 98rpx;
  922. line-height: 98rpx;
  923. background: #f8f8f8;
  924. border: 1px solid #999999;
  925. border-radius: 6rpx;
  926. font-size: 30rpx;
  927. text-align: center;
  928. }
  929. .input-box .tips {
  930. color: #666666;
  931. font-size: 26rpx;
  932. margin-top: 18rpx;
  933. }
  934. .tabs {}
  935. .tabs .tab-tit {
  936. font-size: 30rpx;
  937. color: #333;
  938. padding: 45rpx 0 22rpx 30rpx;
  939. }
  940. .tabs .tab {
  941. display: flex;
  942. flex-wrap: wrap;
  943. justify-content: space-evenly;
  944. }
  945. .tabs .tab .item {
  946. width: 210rpx;
  947. height: 100rpx;
  948. background: #f6fff7;
  949. border: 1px solid #dcdde1;
  950. box-sizing: border-box;
  951. line-height: 100rpx;
  952. border-radius: 6rpx;
  953. text-align: center;
  954. margin-bottom: 24rpx;
  955. color: #333333;
  956. font-size: 32rpx;
  957. }
  958. .tabs .tab .item.active {
  959. border: 1px solid #24cc49;
  960. color: #24cc49;
  961. }
  962. .btn-primary {
  963. width: 670rpx;
  964. height: 80rpx;
  965. line-height: 80rpx;
  966. background: linear-gradient(-90deg, #43a1e0 0%, #13e7c1 100%);
  967. border-radius: 40rpx;
  968. font-size: 32rpx;
  969. color: #ffffff;
  970. margin: 200rpx 40rpx 0;
  971. text-align: center;
  972. }
  973. .uni-list {
  974. padding: 120rpx 10rpx 0 10rpx;
  975. font-size: 34rpx;
  976. }
  977. label {
  978. display: flex;
  979. justify-content: space-between;
  980. margin-top: 30rpx;
  981. }
  982. </style>