Blogger Information
Blog 62
fans 7
comment 2
visits 58122
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
laravel框架之微信扫码支付对接
我是郭富城
Original
1164 people have browsed it

1. 下载php的sdk

https://pay.weixin.qq.com/wiki/doc/api/native.php?chapter=11_1

2. 把下载的sdk源码放到vendor类库

讲文件解压并根据个人喜好放到vendor目录

3. 在商城控制器中添加支付方法

  1. // 支付
  2. public function pay(Request $request) {
  3. // 生成二维码
  4. // echo __DIR__;
  5. // D:\laravel\app\Http\Controllers
  6. // exit;
  7. $wx_pay_path = __DIR__ . '/../../../vendor/wx_pay/';
  8. require_once $wx_pay_path . "lib/WxPay.Api.php";
  9. require_once $wx_pay_path . "example/WxPay.NativePay.php";
  10. // require_once 'log.php';
  11. $notify = new \NativePay();
  12. $input = new \WxPayUnifiedOrder();
  13. $input->SetBody("test");
  14. $input->SetAttach("test");
  15. $input->SetOut_trade_no("sdkphp123456789".date("YmdHis"));
  16. $input->SetTotal_fee("1");
  17. $input->SetTime_start(date("YmdHis"));
  18. $input->SetTime_expire(date("YmdHis", time() + 600));
  19. $input->SetGoods_tag("test");
  20. $input->SetNotify_url("http://paysdk.weixin.qq.com/notify.php");
  21. $input->SetTrade_type("NATIVE");
  22. $input->SetProduct_id("123456789");
  23. $result = $notify->GetPayUrl($input);
  24. $data['url2'] = $result["code_url"];
  25. // echo '<pre>';
  26. // var_dump($result);
  27. return view('shop/pay',$data);
  28. }

4. 在商城控制器中添加二维码生成的方法

  1. public function creatqrcode() {
  2. $wx_pay_path = __DIR__ . '/../../../vendor/wx_pay/';
  3. require_once $wx_pay_path . 'example/phpqrcode/phpqrcode.php';
  4. $url = urldecode($_GET["data"]);
  5. if(substr($url, 0, 6) == "weixin"){
  6. \QRcode::png($url);
  7. }else{
  8. header('HTTP/1.1 404 Not Found');
  9. }
  10. }

5. 填写相关的微信商户信息

目录example下的WxPay.Config.php
修改基本信息

  1. public function GetAppId()
  2. {
  3. // AppID账号
  4. return '微信公众号的appid';
  5. }
  6. public function GetMerchantId()
  7. {
  8. // 微信商户号
  9. return '你的微信商户号';
  10. }
  11. public function GetKey()
  12. {
  13. // API密钥
  14. return '32位的api密钥';
  15. }
  16. public function GetAppSecret()
  17. {
  18. // 公众帐号secert
  19. return '请登录微信公众号,重置一个appsecret';
  20. }

6. 前端付款二维码

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>微信支付二维码</title>
  6. <link rel="stylesheet" href="/static/plugins/layui/css/layui.css">
  7. <link rel="stylesheet" href="/static/css/index.css">
  8. <script src="/static/plugins/layui/layui.js"></script>
  9. </head>
  10. <body>
  11. <div class="wx_pay">
  12. <img alt="扫码支付" src="/shop/creatqrcode?data=<?php echo urlencode($url2);?>" />
  13. </div>
  14. </body>
  15. </html>

7. 效果图

8. 总结

到目前为止,已经可以正常生成预设信息的付款二维码了,取得了阶段性的胜利,下一个博客讲进一步讲解如何获取数据库中的订单信息并产生支付二维码等进阶内容。

Correcting teacher:GuanhuiGuanhui

Correction status:qualified

Teacher's comments:可以!
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post