native.php 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. include("../../../config/conn.php");
  3. $g_webname=iconv("GB2312","UTF-8//IGNORE",webname);
  4. function php_toheader($nurlx){echo "<script>";echo "parent.location.href='".$nurlx."';";echo "</script>";exit;}
  5. $ddbh=$_GET[ddbh];if(empty($ddbh)){echo "wx001";exit;}
  6. $sql="select * from yjcode_dingdang where ddbh='".$ddbh."'";mysql_query("SET NAMES 'GBK'");$res=mysql_query($sql);
  7. if(!$row=mysql_fetch_array($res)){echo "wx002";exit;}
  8. if(1==$row[ifok]){php_toheader("../../paylog.php");}
  9. function updatetable($utable,$ures,$uwhere=""){$sqlupdate="update ".$utable." set ".$ures." ".$uwhere;mysql_query("SET NAMES 'GBK'");mysql_query($sqlupdate);}
  10. ini_set('date.timezone','Asia/Shanghai');
  11. //error_reporting(E_ERROR);
  12. require_once "../lib/WxPay.Api.php";
  13. require_once "WxPay.NativePay.php";
  14. require_once 'log.php';
  15. $notify = new NativePay();
  16. //模式二
  17. /**
  18. * 流程:
  19. * 1、调用统一下单,取得code_url,生成二维码
  20. * 2、用户扫描二维码,进行支付
  21. * 3、支付完成之后,微信服务器会通知支付成功
  22. * 4、在支付成功通知中需要查单确认是否真正支付成功(见:notify.php)
  23. */
  24. $input = new WxPayUnifiedOrder();
  25. $input->SetBody($g_webname);
  26. $input->SetAttach("test");
  27. $wxddbh=WxPayConfig::MCHID.date("YmdHis");if(!empty($row[wxddbh])){$wxddbh=$row[wxddbh];}
  28. $input->SetOut_trade_no($wxddbh);
  29. $input->SetTotal_fee($row[money1]*100);
  30. $input->SetTime_start(date("YmdHis"));
  31. $input->SetTime_expire(date("YmdHis", time() + 600));
  32. $input->SetGoods_tag("test");
  33. $input->SetNotify_url(weburl."user/wxpay/example/notify.php");
  34. $input->SetTrade_type("NATIVE");
  35. $input->SetProduct_id($ddbh);
  36. $result = $notify->GetPayUrl($input);
  37. $url2 = $result["code_url"];
  38. updatetable("yjcode_dingdang","wxddbh='".$wxddbh."' where ddbh='".$ddbh."'");
  39. ?>
  40. <html>
  41. <head>
  42. <meta http-equiv="content-type" content="text/html;charset=utf-8"/>
  43. <meta name="viewport" content="width=device-width, initial-scale=1" />
  44. <title><?=$g_webname?>微信支付</title>
  45. <script language="javascript">
  46. var xmlHttp = false;
  47. try {
  48. xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
  49. } catch (e) {
  50. try {
  51. xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
  52. } catch (e2) {
  53. xmlHttp = false;
  54. }
  55. }
  56. if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
  57. xmlHttp = new XMLHttpRequest();
  58. }
  59. function updatePage() {
  60. if (xmlHttp.readyState == 4) {
  61. var response = xmlHttp.responseText;
  62. response=response.replace(/[\r\n]/g,'');
  63. if(response=="ok"){<? if($_GET[ifwap]=="yes"){$ifm="m/";}?>parent.location.href="<?=weburl.$ifm?>user/paylog.php";}else{setTimeout("yzonc()",2000);return false;}
  64. }
  65. }
  66. function yzonc(){
  67. url = "wxpd.php?ddbh=<?=$ddbh?>";
  68. xmlHttp.open("get", url, true);
  69. xmlHttp.onreadystatechange = updatePage;
  70. xmlHttp.send(null);
  71. }
  72. setTimeout("yzonc()",2000);
  73. function pclo(){parent.layer.close(parent.layer.index);}
  74. </script>
  75. </head>
  76. <body>
  77. <img src="../img/clo.gif" style="float:right;cursor:pointer;" onClick="pclo()" width="52" height="22">
  78. <img alt="模式二扫码支付" style="float:left;clear:both;margin:0 0 0 7px;" src="<?=weburl?>tem/getqr.php?u=<?=urlencode($url2)?>&size=9"/>
  79. <br><br>
  80. <img src="../img/ts.gif" width="261" height="88" style="margin:0 0 0 42px;float:left;clear:both;" >
  81. </body>
  82. </html>