ba833c46881188bdbd5094c3b3012722f602a548.svn-base 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. /**
  3. *
  4. * example目录下为简单的支付样例,仅能用于搭建快速体验微信支付使用
  5. * 样例的作用仅限于指导如何使用sdk,在安全上面仅做了简单处理, 复制使用样例代码时请慎重
  6. * 请勿直接直接使用样例对外提供服务
  7. *
  8. **/
  9. require_once "./lib/WxPay.Api.php";
  10. require_once "WxPay.NativePay.php";
  11. // require_once 'log.php';
  12. //初始化日志
  13. // $logHandler= new CLogFileHandler("../logs/".date('Y-m-d').'.log');
  14. // $log = Log::Init($logHandler, 15);
  15. //模式一
  16. //不再提供模式一支付方式
  17. /**
  18. * 流程:
  19. * 1、组装包含支付信息的url,生成二维码
  20. * 2、用户扫描二维码,进行支付
  21. * 3、确定支付之后,微信服务器会回调预先配置的回调地址,在【微信开放平台-微信支付-支付配置】中进行配置
  22. * 4、在接到回调通知之后,用户进行统一下单支付,并返回支付信息以完成支付(见:native_notify.php)
  23. * 5、支付完成之后,微信服务器会通知支付成功
  24. * 6、在支付成功通知中需要查单确认是否真正支付成功(见:notify.php)
  25. */
  26. $notify = new NativePay();
  27. $url1 = $notify->GetPrePayUrl("123456789");
  28. //模式二
  29. /**
  30. * 流程:
  31. * 1、调用统一下单,取得code_url,生成二维码
  32. * 2、用户扫描二维码,进行支付
  33. * 3、支付完成之后,微信服务器会通知支付成功
  34. * 4、在支付成功通知中需要查单确认是否真正支付成功(见:notify.php)
  35. */
  36. $input = new WxPayUnifiedOrder();
  37. $input->SetBody("test");
  38. $input->SetAttach("test");
  39. $input->SetOut_trade_no("sdkphp123456789".date("YmdHis"));
  40. $input->SetTotal_fee("1");
  41. $input->SetTime_start(date("YmdHis"));
  42. $input->SetTime_expire(date("YmdHis", time() + 600));
  43. $input->SetGoods_tag("test");
  44. $input->SetNotify_url("http://paysdk.weixin.qq.com/notify.php");
  45. $input->SetTrade_type("NATIVE");
  46. $input->SetProduct_id("123456789");
  47. $result = $notify->GetPayUrl($input);
  48. $url2 = $result["code_url"];
  49. ?>
  50. <html>
  51. <head>
  52. <meta http-equiv="content-type" content="text/html;charset=utf-8"/>
  53. <meta name="viewport" content="width=device-width, initial-scale=1" />
  54. <title>微信支付样例-退款</title>
  55. </head>
  56. <body>
  57. <div style="margin-left: 10px;color:#556B2F;font-size:30px;font-weight: bolder;">扫描支付模式一</div><br/>
  58. <img alt="模式一扫码支付" src="qrcode.php?data=<?php echo urlencode($url1);?>" style="width:150px;height:150px;"/>
  59. <br/><br/><br/>
  60. <div style="margin-left: 10px;color:#556B2F;font-size:30px;font-weight: bolder;">扫描支付模式二</div><br/>
  61. <img alt="模式二扫码支付" src="qrcode.php?data=<?php echo urlencode($url2);?>" style="width:150px;height:150px;"/>
  62. <div style="color:#ff0000"><b>微信支付样例程序,仅做参考</b></div>
  63. </body>
  64. </html>