wxPlatformPay.php 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <!doctype html>
  2. <html>
  3. <head>
  4. <meta http-equiv="content-type" content="text/html;charset=utf-8"/>
  5. <meta http-equiv="Expires" CONTENT="0">
  6. <meta http-equiv="Cache-Control" CONTENT="no-cache">
  7. <meta http-equiv="Pragma" CONTENT="no-cache">
  8. <title>微信支付</title>
  9. </head>
  10. <body style="width:100%;height:100%;text-align: center;">
  11. <div style="color:#FFF;margin-top:40px;">
  12. </div>
  13. <script type="text/javascript">
  14. window.alert = function(name){
  15. var iframe = document.createElement("IFRAME");
  16. iframe.style.display="none";
  17. iframe.setAttribute("src", 'data:text/plain,');
  18. document.documentElement.appendChild(iframe);
  19. window.frames[0].window.alert(name);
  20. iframe.parentNode.removeChild(iframe);
  21. };
  22. var is_pay = false;
  23. //调用微信JS api 支付
  24. function jsApiCall()
  25. {
  26. WeixinJSBridge.invoke(
  27. 'getBrandWCPayRequest',<?php echo $jsApiParameters; ?>,
  28. function(res){
  29. if (res.err_msg == 'get_brand_wcpay_request:ok') {//支付成功
  30. goNotice('success');
  31. } else if (res.err_msg == 'get_brand_wcpay_request:cancel') {//支付过程中用户取消
  32. alert('取消支付/(ㄒoㄒ)/~~');
  33. goNotice('cancel');
  34. } else if (res.err_msg == 'get_brand_wcpay_request:fail') {//支付失败
  35. alert('支付失败/(ㄒoㄒ)/~~');
  36. goNotice('fail');
  37. }else{
  38. alert('支付失败/(ㄒoㄒ)/~~');
  39. goNotice('fail');
  40. }
  41. }
  42. );
  43. }
  44. function goNotice(status){
  45. var notifyUrl = '<?php echo $notify_url; ?>';
  46. if(notifyUrl.indexOf('?')==-1){
  47. //不存在的话
  48. notifyUrl += ('?_wxPay_='+status+"&_time_="+Math.random());
  49. }else{
  50. notifyUrl += ('&_wxPay_='+status+"&_time_="+Math.random());
  51. }
  52. window.location.href = notifyUrl;
  53. return false;
  54. }
  55. function callpay()
  56. {
  57. if (typeof WeixinJSBridge == "undefined"){
  58. if( document.addEventListener ){
  59. document.addEventListener('WeixinJSBridgeReady', jsApiCall, false);
  60. }else if (document.attachEvent){
  61. document.attachEvent('WeixinJSBridgeReady', jsApiCall);
  62. document.attachEvent('onWeixinJSBridgeReady', jsApiCall);
  63. }
  64. }else{
  65. jsApiCall();
  66. }
  67. }
  68. function writeObj(obj){
  69. var description = "";
  70. for(var i in obj){
  71. var property=obj[i];
  72. description+=i+" = "+property+"\n";
  73. }
  74. alert(description);
  75. }
  76. callpay();
  77. </script>
  78. </body>
  79. </html>