批改状态:合格
老师批语:可以!
https://pay.weixin.qq.com/wiki/doc/api/native.php?chapter=11_1
讲文件解压并根据个人喜好放到vendor目录
// 支付public function pay(Request $request) {// 生成二维码// echo __DIR__;// D:\laravel\app\Http\Controllers// exit;$wx_pay_path = __DIR__ . '/../../../vendor/wx_pay/';require_once $wx_pay_path . "lib/WxPay.Api.php";require_once $wx_pay_path . "example/WxPay.NativePay.php";// require_once 'log.php';$notify = new \NativePay();$input = new \WxPayUnifiedOrder();$input->SetBody("test");$input->SetAttach("test");$input->SetOut_trade_no("sdkphp123456789".date("YmdHis"));$input->SetTotal_fee("1");$input->SetTime_start(date("YmdHis"));$input->SetTime_expire(date("YmdHis", time() + 600));$input->SetGoods_tag("test");$input->SetNotify_url("http://paysdk.weixin.qq.com/notify.php");$input->SetTrade_type("NATIVE");$input->SetProduct_id("123456789");$result = $notify->GetPayUrl($input);$data['url2'] = $result["code_url"];// echo '<pre>';// var_dump($result);return view('shop/pay',$data);}
public function creatqrcode() {$wx_pay_path = __DIR__ . '/../../../vendor/wx_pay/';require_once $wx_pay_path . 'example/phpqrcode/phpqrcode.php';$url = urldecode($_GET["data"]);if(substr($url, 0, 6) == "weixin"){\QRcode::png($url);}else{header('HTTP/1.1 404 Not Found');}}
目录example下的WxPay.Config.php
修改基本信息
public function GetAppId(){// AppID账号return '微信公众号的appid';}public function GetMerchantId(){// 微信商户号return '你的微信商户号';}public function GetKey(){// API密钥return '32位的api密钥';}public function GetAppSecret(){// 公众帐号secertreturn '请登录微信公众号,重置一个appsecret';}
<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><title>微信支付二维码</title><link rel="stylesheet" href="/static/plugins/layui/css/layui.css"><link rel="stylesheet" href="/static/css/index.css"><script src="/static/plugins/layui/layui.js"></script></head><body><div class="wx_pay"><img alt="扫码支付" src="/shop/creatqrcode?data=<?php echo urlencode($url2);?>" /></div></body></html>

到目前为止,已经可以正常生成预设信息的付款二维码了,取得了阶段性的胜利,下一个博客讲进一步讲解如何获取数据库中的订单信息并产生支付二维码等进阶内容。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号