index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  1. <template>
  2. <div class="mianBox">
  3. <van-row class="headerBox">
  4. <van-icon name="arrow-left" @click="$router.go(-1)" />
  5. 选择充值方式
  6. </van-row>
  7. <van-row class="contentBox">
  8. <van-row>
  9. <!-- <van-col @click="openApp({app:'weixin://dl/scan',downA:'https://dldir1.qq.com/weixin/android/weixin8011android1980_arm64.apk',downI:'https://itunes.apple.com/cn/app/wei/id414478124',})"></van-col> -->
  10. <van-col @click="openApp({app: 'weixin://scanqrcode',downA:'https://dldir1.qq.com/weixin/android/weixin8011android1980_arm64.apk',downI: 'https://itunes.apple.com/cn/app/wei/id414478124',})">
  11. <van-image :src="require('../../assets/image/wx.png')" />
  12. </van-col>
  13. <van-col @click="openApp({app: 'alipayqr',downA:'https://t.alipayobjects.com/L1/71/100/and/alipay_wap_main.apk',downI: 'https://itunes.apple.com/cn/app/id333206289?mt=8',})">
  14. <van-image :src="require('../../assets/image/zfb.png')" />
  15. </van-col>
  16. <!-- 隐藏<van-col @click="openApp({app:'alipayqr://platformapi/startapp?saId=20000067&url=https://blog.csdn.net/sun5769675/article/details/89634633',downA:'https://t.alipayobjects.com/L1/71/100/and/alipay_wap_main.apk',downI:'https://itunes.apple.com/cn/app/id333206289?mt=8',})"></van-col>
  17. 隐藏<van-col @click="openApp({app:'ysf',downA:'https://youhui.95516.com/app/app/software/unionpay-wallet-v2.apk',downI:'https://dl.95862788.com/52/77785',})"></van-col>
  18. <van-col @click="openApp({app:'ysf',downA:'https://youhui.95516.com/app/app/software/unionpay-wallet-v2.apk',downI:'https://youhui.95516.com/hybrid_v4/html/help/download.html?code=ctoc00000000022',})">
  19. <van-image :src="require('../../assets/image/ysf.png')" />
  20. </van-col> -->
  21. </van-row>
  22. <van-row> 请选择微信、支付宝进行充值。</van-row>
  23. <van-row style="color:red;margin-top:4px;" v-if="user && version || user && huawei">(华为、Android10系统在选择微信支付时,需要开启微信的“浮窗”和“允许在其他上层应用上打开”这两个权限) </van-row>
  24. <van-loading
  25. size="24px"
  26. v-if="loading"
  27. vertical
  28. style="z-index: 999999; position: fixed; top: 40%; left: 0; right: 0"
  29. >加载中...</van-loading
  30. >
  31. <van-overlay :show="loading" style="z-index: 100; position: fixed" />
  32. </van-row>
  33. </div>
  34. </template>
  35. <script>
  36. import axios from "axios";
  37. import { Dialog, Notify, Toast } from "vant";
  38. // import { getPayApi} from "@/plugins/common";
  39. export default {
  40. components: {
  41. [Notify.Component.name]: Notify.Component,
  42. [Dialog.Component.name]: Dialog.Component,
  43. },
  44. data() {
  45. return {
  46. iosApp: "",
  47. url: "",
  48. loading: false,
  49. money: null,
  50. channelId: undefined,
  51. userId:undefined,
  52. version:false,
  53. huawei:false,
  54. };
  55. },
  56. mounted() {
  57. //判断安卓版本
  58. var ua = navigator.userAgent.toLowerCase();
  59. if (/android/i.test(navigator.userAgent)) {
  60. var test = /android\s([\w.]+)/;//IE
  61. var match = test.exec(ua);
  62. var version = match[1].split(".")[0];
  63. if(version >= 10){
  64. this.version = true
  65. }
  66. }
  67. var brand = this.judgeBrand(navigator.userAgent.toLowerCase()); //调用机型判断
  68. if(brand == "huawei"){
  69. this.huawei = true
  70. }
  71. // window.document.addEventListener('message', function (e) {
  72. // /*
  73. // * e.data 是APP返回的JSON字符串,字段:
  74. // * eventType 事件类型
  75. // * source 来源
  76. // * data 业务参数 - 返回数据放这里
  77. // * */
  78. // const res = JSON.parse(e.data); // 报文参数
  79. // if(res){
  80. // Toast(res)
  81. // if(res.extMsg == "已支付"){
  82. // window.history.go(-999)
  83. // }
  84. // }
  85. // switch (res.eventType) {
  86. // case "com.launchMiniProgram": { // 扫描二维码成功后的消息
  87. // // Do Something ...
  88. // document.getElementById("text").innerHTML = res.data.data;
  89. // break
  90. // }
  91. // }
  92. // })
  93. },
  94. created() {
  95. this.money = this.$route.query.money;
  96. this.channelId = this.$route.query.channelId;
  97. if(localStorage.getItem("user")){
  98. this.user = localStorage.getItem("user")
  99. }
  100. },
  101. methods: {
  102. judgeBrand(sUserAgent) {
  103. var isIphone = sUserAgent.match(/iphone/i) == "iphone";
  104. var isHuawei = sUserAgent.match(/huawei/i) == "huawei";
  105. var isHonor = sUserAgent.match(/honor/i) == "honor";
  106. var isOppo = sUserAgent.match(/oppo/i) == "oppo";
  107. var isOppoR15 = sUserAgent.match(/pacm00/i) == "pacm00";
  108. var isVivo = sUserAgent.match(/vivo/i) == "vivo";
  109. var isXiaomi = sUserAgent.match(/mi\s/i) == "mi ";
  110. var isXiaomi2s = sUserAgent.match(/mix\s/i) == "mix ";
  111. var isRedmi = sUserAgent.match(/redmi/i) == "redmi";
  112. var isSamsung = sUserAgent.match(/sm-/i) == "sm-";
  113. if (isIphone) {
  114. return 'iphone';
  115. } else if (isHuawei || isHonor) {
  116. return 'huawei';
  117. } else if (isOppo || isOppoR15) {
  118. return 'oppo';
  119. } else if (isVivo) {
  120. return 'vivo';
  121. } else if (isXiaomi || isRedmi || isXiaomi2s) {
  122. return 'xiaomi';
  123. } else if (isSamsung) {
  124. return 'samsung';
  125. } else {
  126. return 'default';
  127. }
  128. },
  129. randomString() {
  130. let len = 32;
  131. let $chars = "ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678";
  132. let maxPos = $chars.length;
  133. let pwd = "";
  134. for (let i = 0; i < len; i++) {
  135. pwd += $chars.charAt(Math.floor(Math.random() * maxPos));
  136. }
  137. return pwd;
  138. },
  139. async pay(money, topPayType, payType, channelId,userId) {
  140. if(userId){
  141. //("返回支付宝app支付链接")
  142. axios.get("dxtop/staff/one",{
  143. params:{
  144. id:localStorage.getItem("user")
  145. }
  146. }).then(res =>{
  147. //console.log(res)
  148. if(res.data?.data?.sid){
  149. //console.log(res.data.data.sid)
  150. axios.post('/dxtop/order/callUnifiedPay', {
  151. "money": money,
  152. "topPayType": topPayType,
  153. "payType": payType,
  154. "scene": 3,
  155. "userId": res.data.data.sid
  156. }).then(res2 => {
  157. this.loading = false;
  158. //console.log(res2)
  159. if(res2.data.code == 500){
  160. Toast(res2.data.msg)
  161. }else{
  162. window.location.href = res2.data.msg
  163. }
  164. }).catch(() => {
  165. this.loading = false;
  166. })
  167. }else{
  168. Toast("用户sid不存在")
  169. }
  170. })
  171. } else if(localStorage.getItem("type")){//返回支付宝微信支付连接
  172. //console.log("返回支付宝微信支付链接 用于扫码url进入 带渠道参数")
  173. axios.post('/dxtop/order/topScanPayApi', {
  174. "money": money,
  175. "topPayType": topPayType,
  176. "payType": payType,
  177. "channelId": localStorage.getItem("type"),
  178. "scene": 2,
  179. }).then(res => {
  180. if(res.data.code == 500){
  181. Toast(res.data.msg)
  182. }else{
  183. window.location.href = res.data.msg
  184. }
  185. }).catch(() => {
  186. })
  187. }else{//返回支付宝微信支付连接
  188. // console.log("返回支付宝微信支付链接 用于url进入 不带渠道参数")
  189. axios.post('/dxtop/order/topScanPayApi', {
  190. "money": money,
  191. "topPayType": topPayType,
  192. "payType": payType,
  193. "channelName":"H5链接进入",
  194. "scene": 2,
  195. }).then(res => {
  196. if(res.data.code == 500){
  197. Toast(res.data.msg)
  198. }else{
  199. window.location.href = res.data.msg
  200. }
  201. }).catch(() => {
  202. })
  203. }
  204. },
  205. weixin(){
  206. // 正式版:0,测试版:1,体验版:2
  207. let params = {
  208. "eventType": "com.launchMiniProgram",
  209. "data": {
  210. userName: 'gh_e9f7d5c76d18',
  211. miniProgramType: 0,
  212. path: `/pages/index/index?money=${this.money}&scene=3&userId=${localStorage.getItem("user")}&channelId=null&openid=null`
  213. }
  214. }
  215. window.ReactNativeWebView.postMessage(JSON.stringify(params));
  216. this.loading = false;
  217. },
  218. async openApp(url = "") {
  219. if (!url) return;
  220. //if (url.app === 'ysf') return Notify({ type: 'primary', message: '暂不可用' });
  221. //if (this.iosApp) return Notify({ type: 'primary', message: '请使用浏览器打开' });
  222. //非微信浏览器
  223. window.navigator.userAgent.toLowerCase();
  224. if (navigator.userAgent.match(/(iPhone|iPod|iPad);?/i)) {
  225. if(this.channelId){//游客支付,A01/W06 不用传
  226. if (url.app === "alipayqr") {
  227. //console.log("苹果游客支付宝url")
  228. this.pay(this.money, "A01", "3", this.channelId);
  229. }else if(url.app === "weixin://scanqrcode"){
  230. //console.log("苹果游客微信支付url")
  231. this.pay(this.money, "W06", "2", this.channelId);
  232. }else{
  233. }
  234. }else if(localStorage.getItem("user")){ //app微信支付
  235. if (url.app === "alipayqr") {
  236. this.loading = true;
  237. //console.log("苹果app支付宝")
  238. this.pay(this.money, "A01", "3", "", localStorage.getItem("user"))
  239. }else if(url.app === "weixin://scanqrcode"){
  240. this.loading = true;
  241. //console.log("苹果app微信小程序")
  242. this.weixin()
  243. }else{
  244. }
  245. }else{
  246. if (url.app === "alipayqr") {
  247. this.pay(this.money, "A01", "3", '');
  248. //console.log("苹果游客支付宝url")
  249. }else if(url.app === "weixin://scanqrcode"){
  250. //console.log("苹果游客微信支付url")
  251. this.pay(this.money, "W06", "2", '');
  252. }else{
  253. }
  254. }
  255. // window.setTimeout(() => {
  256. // const timeOutDateTime = +new Date();
  257. // if (timeOutDateTime - loadDateTime > 2000) {
  258. // window.location.href = url.downI;
  259. // this.loading = false;
  260. // } else {
  261. // window.close();
  262. // this.loading = false;
  263. // Dialog.confirm({
  264. // title: "提示",
  265. // message: "是否已完成充值?",
  266. // })
  267. // .then(() => {
  268. // this.$router.push("/record");
  269. // })
  270. // .catch((e) => {
  271. // console.log(e);
  272. // });
  273. // }
  274. // }, 3000);
  275. } else if (navigator.userAgent.match(/android/i)) {
  276. if(this.channelId){
  277. if (url.app === "alipayqr") {
  278. //console.log("安卓游客支付宝url")
  279. this.pay(this.money, "A01", "3", this.channelId);
  280. }else if(url.app === "weixin://scanqrcode"){
  281. // console.log("安卓游客微信支付url")
  282. this.pay(this.money, "W06", "2", this.channelId);
  283. }else{
  284. }
  285. }else if(localStorage.getItem("user")){
  286. if (url.app === "alipayqr") {
  287. //console.log("苹果app支付宝")
  288. this.pay(this.money, "A01", "3", "",localStorage.getItem("user"));
  289. this.loading = false;
  290. }else if(url.app === "weixin://scanqrcode"){
  291. //console.log("安卓app微信小程序")
  292. this.weixin()
  293. }else{
  294. }
  295. }else{
  296. if (url.app === "alipayqr") {
  297. this.pay(this.money, "A01", "3", 56);
  298. //console.log("苹果游客支付宝url")
  299. }else if(url.app === "weixin://scanqrcode"){
  300. //console.log("苹果游客微信支付url")
  301. this.pay(this.money, "W06", "2", 56);
  302. }else{
  303. }
  304. }
  305. // window.setTimeout(() => {
  306. // const timeOutDateTime = +new Date();
  307. // if (timeOutDateTime - loadDateTime > 2000) {
  308. // window.location.href = url.downI;
  309. // this.loading = false;
  310. // } else {
  311. // window.close();
  312. // this.loading = false;
  313. // Dialog.confirm({
  314. // title: "提示",
  315. // message: "是否已完成充值?",
  316. // })
  317. // .then(() => {
  318. // this.$router.push("/record");
  319. // })
  320. // .catch((e) => {
  321. // console.log(e);
  322. // });
  323. // }
  324. // }, 3000);
  325. }else{
  326. Toast("请使用手机端支付")
  327. }
  328. },
  329. },
  330. };
  331. </script>
  332. <style lang="scss" scoped>
  333. .mianBox {
  334. height: 100%;
  335. width: 100%;
  336. color: #000;
  337. padding-top: 44px;
  338. box-sizing: border-box;
  339. .contentBox {
  340. width: 100%;
  341. height: auto;
  342. padding: 15px 10px;
  343. box-sizing: border-box;
  344. & > .van-row {
  345. display: flex;
  346. justify-content: space-between;
  347. align-items: center;
  348. // height: 86px;
  349. width: 100%;
  350. &::after {
  351. display: none;
  352. }
  353. // & > .van-col {
  354. // width: 100%;
  355. // justify-content: space-between;
  356. // & > .van-image {
  357. // width: 70%;
  358. // margin: 0%;
  359. // }
  360. // }
  361. // & > .van-col:nth-child(1) {
  362. // & > .van-image {
  363. // margin-left: 0%;
  364. // }
  365. // }
  366. // & > .van-col:nth-child(2) {
  367. // & > .van-image {
  368. // margin-left: 15%;
  369. // }
  370. // }
  371. // & > .van-col:nth-child(3) {
  372. // & > .van-image {
  373. // margin-left: 30%;
  374. // }
  375. // }
  376. & > .van-col {
  377. width: 100%;
  378. justify-content: space-between;
  379. & > .van-image {
  380. width: 50%;
  381. margin: 0%;
  382. }
  383. }
  384. & > .van-col:nth-child(1) {
  385. & > .van-image {
  386. margin-left: 25%;
  387. }
  388. }
  389. & > .van-col:nth-child(2) {
  390. & > .van-image {
  391. margin-left: 25%;
  392. }
  393. }
  394. }
  395. & > .van-row:nth-child(2) {
  396. font-size: 16px;
  397. color: #ccc;
  398. margin-top: 10px;
  399. }
  400. }
  401. }
  402. .van-loading--vertical {
  403. color: #fff;
  404. }
  405. </style>