buy_native.php 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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)){php_toheader("../../car.php");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)){php_toheader("../../car.php");exit;}
  8. if(1==$row[ifok]){php_toheader("../../order.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/buy_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"){
  64. <? if($_GET[m]=="yes"){?>
  65. parent.location.href="<?=weburl?>m/user/ordertz.php";
  66. <? }else{?>
  67. parent.location.href="<?=weburl?>user/ordertz.php";
  68. <? }?>
  69. }else{setTimeout("yzonc()",2000);return false;}
  70. }
  71. }
  72. function yzonc(){
  73. url = "wxpd.php?ddbh=<?=$ddbh?>";
  74. xmlHttp.open("get", url, true);
  75. xmlHttp.onreadystatechange = updatePage;
  76. xmlHttp.send(null);
  77. }
  78. setTimeout("yzonc()",2000);
  79. </script>
  80. </head>
  81. <body>
  82. <img alt="模式二扫码支付" style="float:left;clear:both;margin:0 0 0 7px;" src="<?=weburl?>tem/getqr.php?u=<?=urlencode($url2)?>&size=9"/>
  83. <br><br>
  84. <img src="../img/ts.gif" width="261" height="88" style="margin:0 0 0 42px;float:left;clear:both;" >
  85. </body>
  86. </html>