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.

recharge.vue 26KB

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