1 <script type="text/javascript">
2
3 var myTimer;
4 var strcode = 'HTTPS://QR.ALIPAY.COM/FKX06368SFHS1MACJD0L03';
5
6 function timer(intDiff) {
7 myTimer = window.setInterval(function () {
8 var day = 0,
9 hour = 0,
10 minute = 0,
11 second = 0;//时间默认值
12 if (intDiff > 0) {
13 day = Math.floor(intDiff / (60 * 60 * 24));
14 hour = Math.floor(intDiff / (60 * 60)) - (day * 24);
15 minute = Math.floor(intDiff / 60) - (day * 24 * 60) - (hour * 60);
16 second = Math.floor(intDiff) - (day * 24 * 60 * 60) - (hour * 60 * 60) - (minute * 60);
17 }
18 if (minute <= 9) minute = '0' + minute;
19 if (second <= 9) second = '0' + second;
20 $('#hour_show').html('<s id="h"></s>' + hour + '时');
21 $('#minute_show').html('<s></s>' + minute + '分');
22 $('#second_show').html('<s></s>' + second + '秒');
23 if (hour <= 0 && minute <= 0 && second <= 0) {
24 qrcode_timeout();
25 clearInterval(myTimer);
26 }
27 intDiff--;
28
29 if (strcode != ""){
30 checkdata();
31 }
32
33 }, 2000);
34 }
35
36 function checkdata(){
37 $.post(
38 "/getresult",
39 {
40 paysapi_id : "babc6773eba8a7ae22c13d3a",
41 },
42 function(data){
43 if (data.code > 0){
44 window.clearInterval(timer);
45 $("#show_qrcode").attr("src","images/pay_ok.png");
46 $("#use").remove();
47 $("#money").text("支付成功");
48 $("#msg").html("<h1>即将返回商家页</h1>");
49 if (isMobile() == 1){
50 $(".paybtn").html('<a href="' + data.url + '" class="btn btn-primary">返回商家页</a>');
51 setTimeout(function(){
52 // window.location = data.url;
53 location.replace(data.url)
54 }, 3000);
55 }else{
56 $("#msg").html("<h1>即将<a href='https://www.paysapi.com/'>跳转</a>回商家页</h1>");
57 setTimeout(function(){
58 // window.location = data.url;
59 location.replace(data.url)
60 }, 3000);
61 }
62
63 }
64 }
65 );
66 }
67
68 function qrcode_timeout(){
69 $('#show_qrcode').attr("src","images/qrcode_timeout.png");
70 $("#use").hide();
71 $('#msg').html("<h1>请刷新本页</h1>");
72
73 }
74
75 function isWeixin() {
76 var ua = window.navigator.userAgent.toLowerCase();
77 if (ua.match(/MicroMessenger/i) == 'micromessenger') {
78 return 1;
79 } else {
80 return 0;
81 }
82 }
83
84 function isMobile() {
85 var ua = navigator.userAgent.toLowerCase();
86 _long_matches = 'googlebot-mobile|android|avantgo|blackberry|blazer|elaine|hiptop|ip(hone|od)|kindle|midp|mmp|mobile|o2|opera mini|palm( os)?|pda|plucker|pocket|psp|smartphone|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce; (iemobile|ppc)|xiino|maemo|fennec';
87 _long_matches = new RegExp(_long_matches);
88 _short_matches = '1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|e\-|e\/|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(di|rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|xda(\-|2|g)|yas\-|your|zeto|zte\-';
89 _short_matches = new RegExp(_short_matches);
90 if (_long_matches.test(ua)) {
91 return 1;
92 }
93 user_agent = ua.substring(0, 4);
94 if (_short_matches.test(user_agent)) {
95 return 1;
96 }
97 return 0;
98 }
99 //本地生成二维码
100 function showCodeImage(){
101 var qrcode = $('#qrcode').qrcode({
102 text: 'HTTPS://QR.ALIPAY.COM/FKX06368SFHS1MACJD0L03',
103 width: 200,
104 height: 200,
105 }).hide();
106 //添加文字
107 var outTime = '过期时间:2018-04-08 23:09:22';//过期时间
108 var canvas = qrcode.find('canvas').get(0);
109 var oldCtx = canvas.getContext('2d');
110 var imgCanvas = document.getElementById('imgCanvas');
111 var ctx = imgCanvas.getContext('2d');
112 ctx.fillStyle = 'white';
113 ctx.fillRect(0,0,310,270);
114 ctx.putImageData(oldCtx.getImageData(0, 0, 200, 200), 55, 20);
115 //ctx.stroke = 3;
116 ctx.textBaseline = 'middle';
117 ctx.textAlign = 'center';
118 ctx.font ="15px Arial";
119 ctx.fillStyle = '#00c800';
120 ctx.strokeStyle = '#00c800'
121 ctx.fillText(outTime, imgCanvas.width / 2, 235 );
122 ctx.strokeText(outTime, imgCanvas.width / 2, 235);
123
124 var about = '过期后请勿支付,不自动到账';
125 ctx.fillText(about, imgCanvas.width / 2, 260 );
126 ctx.strokeText(about, imgCanvas.width / 2, 260);
127
128 imgCanvas.style.display = 'none';
129 $('#show_qrcode').attr('src', imgCanvas.toDataURL('image/png')).css({
130 width: 310,height:270
131 });
132 // $('#downloadbtn').attr('href', imgCanvas.toDataURL('image/png'));
133 }
134
135 $().ready(function(){
136 //默认6分钟过期
137 timer("300");
138 var istype = "1";
139 var suremoney = "1";
140 var uaa = navigator.userAgent;
141 var isiOS = !!uaa.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
142 if (isMobile() == 1){
143 if (isWeixin() == 1 && istype == 2){
144 //微信内置浏览器+微信支付
145 $("#showtext").text("长按二维码识别");
146 } else{
147 //其他手机浏览器+支付宝支付
148 if (isWeixin() == 0 && istype == 1){
149 $(".paybtn").attr('style','');
150 var goPay = '<span id="goPay"> <span>';
151 //给A标签中的文字添加一个能被jQuery捕获的元素
152 $('#alipaybtn').append(goPay);
153 //模拟点击A标签中的文字
154 $('#goPay').click();
155
156 $('#msg').html("<h1>支付完成后,请返回此页</h1>");
157 $(".qrcode-img-wrapper").remove();
158 $(".tip").remove();
159 $(".foot").remove();
160
161 //$(location).attr('href', 'HTTPS://QR.ALIPAY.COM/FKX06368SFHS1MACJD0L03');
162 } else {
163 if (isWeixin() == 0 && istype == 2){
164 //其他手机浏览器+微信支付
165 //IOS的排除掉
166 if (isiOS){
167 // showCodeImage();
168
169 $('.iospayweixinbtn').attr('style','padding-top: 15px;');
170 }else{
171 $(".payweixinbtn").attr('style','padding-top: 15px;');
172 }
173 $("#showtext").html("请保存二维码到手机<br>微信扫一扫点右上角-从相册选取");
174 }
175 }
176 }
177 }
178
179
180 if (isiOS){
181 $('#show_qrcode').css({width: 310,height:310});
182 }else{
183 var show_expire_time = '1523200162';
184 if(show_expire_time!='0'){
185 if (document.getElementById("imgCanvas").getContext){
186 try {
187 showCodeImage();
188 } catch (error) {
189 $('#show_qrcode').attr('src', "http://mobile.qq.com/qrcode?url=HTTPS://QR.ALIPAY.COM/FKX06368SFHS1MACJD0L03");
190 }
191 }else{
192 $('#show_qrcode').attr('src', "http://mobile.qq.com/qrcode?url=HTTPS://QR.ALIPAY.COM/FKX06368SFHS1MACJD0L03");
193 // $('#downloadbtn').attr('href', "http://mobile.qq.com/qrcode?url=HTTPS://QR.ALIPAY.COM/FKX06368SFHS1MACJD0L03");
194 }
195 }else{
196 $('#show_qrcode').attr('src', "http://mobile.qq.com/qrcode?url=HTTPS://QR.ALIPAY.COM/FKX06368SFHS1MACJD0L03");
197 // $('#downloadbtn').attr('href', "http://mobile.qq.com/qrcode?url=HTTPS://QR.ALIPAY.COM/FKX06368SFHS1MACJD0L03");
198 }
199 }
200
201 });
202
203
204
205 </script>