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