wxPay.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. window.alert = function(name){
  21. var iframe = document.createElement("IFRAME");
  22. iframe.style.display="none";
  23. iframe.setAttribute("src", 'data:text/plain,');
  24. document.documentElement.appendChild(iframe);
  25. window.frames[0].window.alert(name);
  26. iframe.parentNode.removeChild(iframe);
  27. };
  28. //调用微信JS api 支付
  29. function jsApiCall()
  30. {
  31. WeixinJSBridge.invoke(
  32. 'getBrandWCPayRequest',<?php echo $jsApiParameters; ?>,
  33. function(res){
  34. if (res.err_msg == 'get_brand_wcpay_request:ok') {//支付成功
  35. goNotice();
  36. } else if (res.err_msg == 'get_brand_wcpay_request:cancel') {//支付过程中用户取消
  37. alert('取消支付/(ㄒoㄒ)/~~');
  38. goNotice();
  39. } else if (res.err_msg == 'get_brand_wcpay_request:fail') {//支付失败
  40. alert('支付失败/(ㄒoㄒ)/~~');
  41. goNotice();
  42. }
  43. }
  44. );
  45. }
  46. function goNotice(){
  47. window.location.href = '<?php echo $notify_url; ?>';
  48. return true;
  49. }
  50. function callpay()
  51. {
  52. if (typeof WeixinJSBridge == "undefined"){
  53. if( document.addEventListener ){
  54. document.addEventListener('WeixinJSBridgeReady', jsApiCall, false);
  55. }else if (document.attachEvent){
  56. document.attachEvent('WeixinJSBridgeReady', jsApiCall);
  57. document.attachEvent('onWeixinJSBridgeReady', jsApiCall);
  58. }
  59. }else{
  60. jsApiCall();
  61. }
  62. }
  63. function writeObj(obj){
  64. var description = "";
  65. for(var i in obj){
  66. var property=obj[i];
  67. description+=i+" = "+property+"\n";
  68. }
  69. alert(description);
  70. }
  71. callpay();
  72. </script>
  73. </body>
  74. </html>
  75. <?php exit;?>