wxPlatformPay.php 3.2 KB

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