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

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