最近、WeChat のスキャン コード支払いに苦労しています。WeChat の公式ドキュメントを読み、多くの Web ページを検索しましたが、ドキュメントやデモと一致しないことがわかりました (ファイル名は変更しました)投稿して共有します
1. 便利な公式 lib ファイルと関連ファイルをベンダーに配置します
2. 同じ支払いインターフェースを呼び出します
<span>//<span>调用同一支付接口<br><span>public function <span>native(<span>$v_oid<span>=<span>'',<span>$v_amount<span>=<span>''){<br><span>ini_set(<span>'date.timezone',<span>'Asia/Shanghai');<br><span>error_reporting(<span>E_ERROR);<br><span>//<span>添加相关的类文件<br><span><span>vendor(<span>'Wxpay.WxPayApi');<br><span>vendor(<span>'Wxpay.log');<br><span>vendor(<span>'Wxpay.NativePay');<br><span>//<span>初始化日志<br><span><span>$logHandler<span>= new \<span>CLogFileHandler(<span>"../logs/"<span>.<span>date(<span>'Y-m-d')<span>.<span>'.log');<br><span>$log <span>= \<span>Log<span>::<span>Init(<span>$logHandler, <span>15);<br><span>//<span>接受订单信息<br><span><span>if(<span>trim(<span>$v_oid)<span><><span>"") <span>//<span>判断是否有传递订单号<br><span> {<br><span>$v_oid <span>= <span>trim(<span>$v_oid);<br> }<br><span>else<br><span> {<br><span>$this<span>-><span>error(<span>'<span>订单号为空<span>',<span>U(<span>'User/index'));<br><span>exit;<br> }<br><span>$v_amount <span>= <span>trim(<span>$v_amount<span>*<span>100); <span>//<span>支付金额<br><span><br><span><span>//<span>调用同一支付接口<br><span><span>$notify <span>= new \<span>NativePay();<br><span>$input <span>= new \<span>WxPayUnifiedOrder();<br><span>//<span>商品描述<span>----------------------------<span>需要参数传递<span>/<span>统一信息<br><span><span>$input<span>-><span>SetBody(<span>"<span>商品描述位置<span>");<br><span>//<span>附加数据<br><span><span>$input<span>-><span>SetAttach(<span>"<span>附加数据位置<span>");<br><span>//<span>商户订单号<br><span><span>$input<span>-><span>SetOut_trade_no(<span>$v_oid);<br><span>//<span>总金额<br><span><span>$input<span>-><span>SetTotal_fee(<span>$v_amount);<br><span>//<span>开始时间<br><span><span>$input<span>-><span>SetTime_start(<span>date(<span>"YmdHis"));<br><span>//<span>结束时间<br><span><span>$input<span>-><span>SetTime_expire(<span>date(<span>"YmdHis", <span>time() <span>+ <span>600));<br><span>//<span>商品标记<br><span><span>$input<span>-><span>SetGoods_tag(<span>"<span>商品标记位置<span>");<br><span>//<span>异步通知地址<span>,<span>不能携带任何参数<br><span><span>$input<span>-><span>SetNotify_url(<span>U(<span>'NotifyProcess'));<br><span>//<span>交易类型<br><span><span>$input<span>-><span>SetTrade_type(<span>"NATIVE");<br><span>//<span>商品<span>id<br><span><span>$input<span>-><span>SetProduct_id(<span>"123456789");<br><span>//<span>获取同一支付接口结果<br><span><span>$result <span>= <span>$notify<span>-><span>GetPayUrl(<span>$input);<br><span>$url2 <span>= <span>$result[<span>"code_url"];<br><span>$this<span>-><span>assign(<span>'data',<span>urlencode(<span>$url2));<br><span>$this<span>-><span>assign('v_oid',$v_oid); $this->assign('v_amount',$v_amount/100); $this->display();}三.生成二维码</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>