Maison > développement back-end > tutoriel php > ThinkPHP微信扫码支付接口

ThinkPHP微信扫码支付接口

WBOY
Libérer: 2016-07-29 08:56:01
original
931 Les gens l'ont consulté

最近折腾微信扫码支付,看了微信官方文档,找了很多网页,发现和文档/demo不匹配,现在自己算是弄出来了(文件名称有所更改),贴出来分享一下

一.将有用的官方lib文件和使用的相关文件放置到vendor当中

二.调用同一支付接口

WechatController

<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>
Copier après la connexion
<span><span>三.</span><span><span>微信支付生成二维码</span><br><span>public function <span>qrcode(){<br><span>error_reporting(<span>E_ERROR);<br><span>vendor(<span>'Wxpay.phpqrcode.phpqrcode');<br><span>$url <span>= <span>$_GET[<span>"data"];<br>    \<span>QRcode<span>::<span>png(<span>$url);<br>}<br></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span><br><span>四.异步处理</span><br><span>具体处理流程和方式按个人需求</span>
Copier après la connexion
<br><span>//<span>微信异步查询订单机制<br><span>public function <span>Queryorder(<span>$transaction_id)<br>{<br><span>$input <span>= new \<span>WxPayOrderQuery();<br><span>$input<span>-><span>SetTransaction_id(<span>$transaction_id);<br><span>$result <span>= \<span>WxPayApi<span>::<span>orderQuery(<span>$input);<br>    \<span>Log<span>::<span>DEBUG(<span>"query:" <span>. <span>json_encode(<span>$result));<br><span>if(<span>array_key_exists(<span>"return_code", <span>$result)<br><span>&& <span>array_key_exists(<span>"result_code", <span>$result)<br><span>&& <span>$result[<span>"return_code"] <span>== <span>"SUCCESS"<br><span><span>&& <span>$result[<span>"result_code"] <span>== <span>"SUCCESS")<br>    {<br><span>return true;<br>    }<br><span>return false;<br>}<br></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>五.再来个form表单展示二维码</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>
Copier après la connexion
<span>form <span>action=<span>"" <span>method=<span>"post" <span>id=<span>"myForm-table"><br>    h2><span>订单信息<span>h2><br>    div <span>class=<span>"orderNumber"><br>        p <span>class=<span>"a"><span>订单号:<span>"{$v_oid}"<span>p><br>        p <span>class=<span>"b"><br>            span <span>class=<span>"left"><span>应付金额:strong>em><span>{$v_amount}<span>em><span>元<span>strong><span>span><br>            span <span>class=<span>"right"><span>付款后,飞行之翼客服会与您联系,如有问题请咨询<span>24<span>小时飞行热线 <span>400-700-2016<span>span><br>        <span>p><br>    <span>div><br>    h2><span>微信支付<span>h2><br>    img <span>src=<span>"{:U('qrcode')}?data={$data}" <span>alt=<span>"<span>微信扫码<span>"><br>    div <span>class=<span>"order-submit">a <span>href=<span>"javascript:<span>history<span>.<span>go<span>(-1);" <span>class=<span>"submitOrder Order"><span>返回其他支付方式<span>a><span>div><br><span>form></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><br><span>成功的图就不附上了,这是我遇到的问题,由于要重构,所以比较乱,无效代码也比较多,需要整理,记录下来,分享一二</span>
Copier après la connexion
<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>
Copier après la connexion
<br>
Copier après la connexion

以上就介绍了ThinkPHP微信扫码支付接口,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

Étiquettes associées:
source:php.cn
Déclaration de ce site Web
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn
Tutoriels populaires
Plus>
Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal