wxpay.html 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
  7. <link rel="icon" href="//static.hoolihome.com/www/assets/images/hooli.ico">
  8. <title>海外租房_留学生租房_留学生公寓 - hooli官网</title>
  9. <meta name="keywords" contect="留学生公寓,留学租房,留学买房,海外租房价格,海外租房多少钱,海外租房,海外购房,海外买房,海外生活服务">
  10. <meta name="description" contect="hooli,出国留学租房买房首选平台,房源遍布全球热门留学国家500+城市,提供200000+房间,覆盖各大海外高校,实时更新最新留学租房买房、留学生公寓、海外房产等房源信息,信息真实有效,欢迎免费咨询。">
  11. <script type="text/javascript" src="//unpkg.com/vue@2.6.6/dist/vue.min.js"></script>
  12. <!-- <script type="text/javascript" src="//unpkg.com/axios@0.18.0/dist/axios.min.js"></script> -->
  13. <script type="text/javascript" src="//unpkg.com/crypto-js@3.1.9-1/crypto-js.js"></script>
  14. <script src="//cdn.bootcss.com/jquery/2.1.4/jquery.min.js"></script>
  15. <script type="text/javascript" src="//unpkg.com/qs@6.6.0/dist/qs.js"></script>
  16. <style type="text/css">
  17. * {
  18. margin: 0;
  19. padding: 0;
  20. box-sizing: border-box;
  21. }
  22. html,body {
  23. width: 100%;
  24. height: 100%;
  25. }
  26. .van-nav-bar{
  27. height: 44px;
  28. position: relative;
  29. -webkit-user-select: none;
  30. -moz-user-select: none;
  31. -ms-user-select: none;
  32. user-select: none;
  33. text-align: center;
  34. line-height: 44px;
  35. background-color: #fff;
  36. border-bottom: 1px solid #eaeaea;
  37. }
  38. .van-nav-bar .van-nav-bar__left{
  39. bottom: 0;
  40. font-size: 14px;
  41. position: absolute;
  42. width: 33px;
  43. left: 15px;
  44. height: 100%;
  45. display: flex;
  46. align-items: center;
  47. justify-content: center;
  48. }
  49. .goback{
  50. width: 20px;
  51. }
  52. .van-nav-bar__title {
  53. margin: 0 auto;
  54. max-width: 60%;
  55. font-size: 17px;
  56. font-weight: 500;
  57. color: #000;
  58. overflow: hidden;
  59. white-space: nowrap;
  60. text-overflow: ellipsis;
  61. }
  62. #pay-btn {
  63. position: fixed;
  64. bottom: 30px;
  65. width: 100%;
  66. }
  67. #pay-btn div{
  68. display: flex;
  69. align-items: center;
  70. justify-content: center;
  71. height: 45px;
  72. font-size: 18px;
  73. background: #ff523d;
  74. border-radius: 25px;
  75. color: #fff;
  76. border: 0;
  77. margin: 15px 20px;
  78. }
  79. #pay-btn[disabled] div {
  80. background: #ffbfab;
  81. }
  82. .wrap .info {
  83. height: 100px;
  84. background: #fff;
  85. margin-bottom: 10px;
  86. display: flex;
  87. align-items: baseline;
  88. padding: 50px 0 0;
  89. justify-content: center;
  90. }
  91. .wrap .info span {
  92. font-size: 18px;
  93. color: #222;
  94. }
  95. .wrap .info p {
  96. font-size: 40px;
  97. line-height: 45px;
  98. color: #222;
  99. }
  100. </style>
  101. </head>
  102. <body onload="bodyOnLoad()">
  103. <div id="app">
  104. <div class="van-hairline--bottom van-nav-bar">
  105. <div class="van-nav-bar__left" @click="handleBack">
  106. <img class="goback" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAABq0lEQVRYR+3Wv2sUURTF8U9QFIQIQbQSEdIGrAx2lhYWgoJYmEK0SJPKwqQRGxFUUBDBSistLBTUJo29f4CFhUVILYgkWPmDA29hXCX7dmbcbXKbLebNnu875753Z8aUa2bK+nYB/ocDe3AXV/EQt3aKuW+AObzG6SK6iWOTAljAWxwvgj9xDc8mAXAOL3CgiH3FBbwfdcq6RpD3bw7l/BFnsTFKPM+7AGS32XV2P6hXuIzvNeJdAJJz8k7uqR9Yxf1a4cG6Ng6kw9Pp6fhUdd7/ghsXYAUPkLOeGivvLgD78ARXuuTdFuAI3uFk17zbAnzAYh959wHwBRdrLpja01DThIfxBqcaEazhXq3ITutqAPL+XjzF0jSasLmBZTwqQBM9hk2IRJFTcajRmJew3iaS2giG//togThRHmT0ZijdHheiLUB09pdhdL4hGmfixnYtSBeAgcYN3GlM1k9lHH+ugegDIDpn8BIHi+i3cl+M7Iu+AKI7Xxoxv6lfyPB63Mc9UONm1sSBOBFHUluYnSRAtOJqPsuv4/nQ5fUXS58R1Lr0x7pdgKk78BuNnUQhl5vndwAAAABJRU5ErkJggg==" alt="">
  107. </div>
  108. <div class="van-ellipsis van-nav-bar__title">微信支付</div>
  109. </div>
  110. <div class="wrap">
  111. <div class="info" v-if="dataObj.moneySymbol && isRequest">
  112. <span>{{dataObj.moneySymbol}}</span>
  113. <p>{{dataObj.otPrice}}</p>
  114. </div>
  115. <div class="info" v-if="!dataObj.moneySymbol && isRequest">数据加载失败</div>
  116. </div>
  117. <div id="pay-btn" @click="handleGoPay" :disabled="!isRequest">
  118. <div>立即支付</div>
  119. </div>
  120. </div>
  121. <script>
  122. var js_api_param = null;
  123. var jsWxPay = new function(){
  124. var me = this,
  125. app = null;
  126. me.init = function(){
  127. app = new Vue({
  128. el: '#app',
  129. data: function() {
  130. return {
  131. query: {},
  132. dataObj: {
  133. moneySymbol: ''
  134. },
  135. isRequest: false,
  136. paramsObj: {}
  137. }
  138. },
  139. created: function() {
  140. var query = GetRequest();
  141. this.query = query;
  142. var paramsObj = decrypt(this.query.paramsObj);
  143. this.paramsObj = JSON.parse(paramsObj)
  144. window.alert = function (name) {
  145. var iframe = document.createElement('IFRAME');
  146. iframe.style.display = 'none';
  147. iframe.setAttribute('src', 'data:text/plain,');
  148. document.documentElement.appendChild(iframe);
  149. window.frames[0].window.alert(name);
  150. iframe.parentNode.removeChild(iframe);
  151. };
  152. },
  153. mounted() {
  154. this.loadData();
  155. },
  156. methods: {
  157. loadData: function(){
  158. var that = this;
  159. $.ajax({
  160. type: "POST",
  161. url: "https://api.hoolihome.com/hpay/wiseCashier/weChatPay.do",
  162. data: this.paramsObj,
  163. dataType: "json",
  164. success: function(res){
  165. if (res.code == 0) {
  166. that.dataObj = res.data;
  167. that.isRequest = true;
  168. var dom = document.getElementById('pay-btn');
  169. dom.click();
  170. }else{
  171. that.isRequest = true;
  172. alert('微信支付失败,'+code);
  173. }
  174. },
  175. error: function(e){
  176. that.isRequest = true;
  177. alert('微信支付失败,请返回上一页继续支付。')
  178. }
  179. });
  180. // axios({
  181. // url: apiUrl,
  182. // method: 'post',
  183. // headers: {
  184. // // 'X-Requested-With': 'XMLHttpRequest',
  185. // // "Content-Type": "application/x-www-form-urlencoded"
  186. // },
  187. // responseType: "json",
  188. // data: this.paramsObj,
  189. // // transformRequest: [
  190. // // function(data) {
  191. // // return Qs.stringify(data, {
  192. // // arrayFormat: "brackets"
  193. // // });
  194. // // }
  195. // // ]
  196. // }).then(function(response){
  197. // alert(JSON.stringify(response))
  198. // var data = response.data,
  199. // status = response.status;
  200. // if (status === 200) {
  201. // var code = data.code;
  202. // code = parseInt(code);
  203. // if (code === 0) {
  204. // that.dataObj = data;
  205. // that.isRequest = true;
  206. // var dom = document.getElementById('pay-btn');
  207. // dom.click();
  208. // }else{
  209. // alert('微信支付失败,'+code);
  210. // }
  211. // }else{
  212. // alert('微信支付失败');
  213. // }
  214. // }).catch(function(e){
  215. // that.msg = JSON.stringify(e)
  216. // alert('微信支付失败,请返回上一页继续支付。' + JSON.stringify(e))
  217. // })
  218. },
  219. handleGoPay: function() {
  220. if(js_api_param){
  221. jsApiCall();
  222. return;
  223. }
  224. var that = this;
  225. var params = {
  226. merchant_no: that.dataObj.merchantNo,
  227. amount: that.dataObj.otPrice,
  228. openid: that.dataObj.openId,
  229. currency: that.query.currency,
  230. product_info: that.dataObj.productInfo,
  231. agent_order_id: that.dataObj.agentOrderId,
  232. notify_url: that.dataObj.notifyUrl
  233. }
  234. that.isRequest = false;
  235. $.ajax({
  236. type: "POST",
  237. url: "/mp_pay",
  238. data: params,
  239. dataType: "json",
  240. headers: {
  241. 'Version': '1.0'
  242. },
  243. success: function(r){
  244. // alert('微信支付success,'+JSON.stringify(r))
  245. that.isRequest = true;
  246. if (r.meta.success) {
  247. js_api_param = r.data.js_param;
  248. if (typeof WeixinJSBridge == "undefined") {
  249. if (document.addEventListener) {
  250. document.addEventListener('WeixinJSBridgeReady', jsApiCall, false);
  251. } else if (document.attachEvent) {
  252. document.attachEvent('WeixinJSBridgeReady', jsApiCall);
  253. document.attachEvent('onWeixinJSBridgeReady', jsApiCall);
  254. }
  255. } else {
  256. jsApiCall();
  257. }
  258. }
  259. },
  260. error: function(e){
  261. that.isRequest = true;
  262. alert('微信支付失败,请返回上一页继续支付。')
  263. }
  264. });
  265. // var that = this;
  266. // var apiUrl = '/mp_pay';
  267. // var params = {
  268. // merchant_no: that.dataObj.data.merchantNo,
  269. // amount: that.dataObj.data.otPrice,
  270. // openid: that.dataObj.data.openId,
  271. // currency: that.query.currency,
  272. // product_info: that.dataObj.data.productInfo,
  273. // agent_order_id: that.dataObj.data.agentOrderId,
  274. // notify_url: that.dataObj.data.notifyUrl
  275. // }
  276. // axios({
  277. // url: apiUrl,
  278. // method: 'post',
  279. // headers: {
  280. // 'Version': '1.0'
  281. // },
  282. // responseType: "json",
  283. // data: params,
  284. // transformRequest: [
  285. // function(data) {
  286. // return Qs.stringify(data, {
  287. // arrayFormat: "brackets"
  288. // });
  289. // }
  290. // ]
  291. // })
  292. // .then(function (r) {
  293. // var data = r.data;
  294. // if (data.meta.success) {
  295. // js_api_param = data.data.js_param;
  296. // if (typeof WeixinJSBridge == "undefined") {
  297. // if (document.addEventListener) {
  298. // document.addEventListener('WeixinJSBridgeReady', jsApiCall, false);
  299. // } else if (document.attachEvent) {
  300. // document.attachEvent('WeixinJSBridgeReady', jsApiCall);
  301. // document.attachEvent('onWeixinJSBridgeReady', jsApiCall);
  302. // }
  303. // } else {
  304. // jsApiCall();
  305. // }
  306. // }
  307. // })
  308. // .catch(function (e) {
  309. // console.log(e);
  310. // });
  311. },
  312. handleBack: function(){
  313. window.history.go(-1);
  314. }
  315. }
  316. });
  317. };
  318. }
  319. //调用微信JS api 支付
  320. function jsApiCall() {
  321. WeixinJSBridge.invoke('getBrandWCPayRequest', js_api_param, function (res) {
  322. var originHost = GetRequest().originHost || 'm.hoolihome.com'
  323. if (res.err_msg == "get_brand_wcpay_request:ok") {
  324. window.location.href = originHost+'/success'
  325. }
  326. if (res.err_msg == "get_brand_wcpay_request:fail") {
  327. alert('支付失败');
  328. window.history.go(-1);
  329. }
  330. });
  331. }
  332. function decrypt(word) {
  333. const CryptoJSKey = CryptoJS.enc.Utf8.parse("1234123412ABCDEF"); //十六位十六进制数作为密钥
  334. const CryptoJSiv = CryptoJS.enc.Utf8.parse("ABCDEF1234123412"); //十六位十六进制数作为密钥偏移量
  335. var encryptedHexStr = CryptoJS.enc.Hex.parse(word);
  336. var srcs = CryptoJS.enc.Base64.stringify(encryptedHexStr);
  337. var decrypt = CryptoJS.AES.decrypt(srcs, CryptoJSKey, {
  338. iv: CryptoJSiv,
  339. mode: CryptoJS.mode.CBC,
  340. padding: CryptoJS.pad.Pkcs7
  341. });
  342. var decryptedStr = decrypt.toString(CryptoJS.enc.Utf8);
  343. return decryptedStr.toString();
  344. }
  345. function getQueryString(name) {
  346. var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
  347. var r = window.location.search.substr(1).match(reg);
  348. if (r != null) return unescape(r[2]);
  349. return null;
  350. }
  351. function GetRequest() {
  352. var url = location.search; //获取url中"?"符后的字串
  353. var theRequest = {};
  354. if (url.indexOf("?") != -1) {
  355. var str = url.substr(1);
  356. strs = str.split("&");
  357. for(var i = 0; i < strs.length; i ++) {
  358. theRequest[strs[i].split("=")[0]]=unescape(strs[i].split("=")[1]);
  359. }
  360. }
  361. return theRequest;
  362. }
  363. function bodyOnLoad(){
  364. jsWxPay.init();
  365. }
  366. </script>
  367. </body>
  368. </html>