ThinkPHP微信扫码支付接口,thinkphp支付接口
ThinkPHP微信扫码支付接口,thinkphp支付接口
最近折腾微信扫码支付,看了微信官方文档,找了很多网页,发现和文档/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 /><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 /><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>
<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>
<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 /><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><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>form <span>action=<span>"" <span>method=<span>"post" <span>id=<span>"myForm-table"><br /> <<span>h2><span>订单信息</<span>h2><br /> <<span>div <span>class=<span>"orderNumber"><br /> <<span>p <span>class=<span>"a"><span>订单号:<span>"{$v_oid}"</<span>p><br /> <<span>p <span>class=<span>"b"><br /> <<span>span <span>class=<span>"left"><span>应付金额:<<span>strong><<span>em><span>{$v_amount}</<span>em><span>元</<span>strong></<span>span><br /> <<span>span <span>class=<span>"right"><span>付款后,飞行之翼客服会与您联系,如有问题请咨询<span>24<span>小时飞行热线 <span>400-700-2016</<span>span><br /> </<span>p><br /> </<span>div><br /> <<span>h2><span>微信支付</<span>h2><br /> <<span>img <span>src=<span>"{:U('qrcode')}?data={$data}" <span>alt=<span>"<span>微信扫码<span>"><br /> <<span>div <span>class=<span>"order-submit"><<span>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></span></span></span></span></span></span></span></span></span></span></span></span></span><br /><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></span></span></span>
<br /><br />

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Thanks to netizens Qing Qiechensi, HH_KK, Satomi Ishihara and Wu Yanzu of South China for submitting clues! According to news on September 2, there are recent rumors that "iPhone 16 may not support WeChat." In response to this, a reporter from Shell Finance called Apple's official hotline. Apple's technical consultant in China responded that whether iOS systems or Apple devices can continue to use WeChat, and WeChat The issue of whether it can continue to be listed and downloaded on the Apple App Store requires communication and discussion between Apple and Tencent to determine the future situation. Software App Store and WeChat Problem Description Software App Store technical consultant pointed out that developers may need to pay fees to put software on the Apple Store. After reaching a certain number of downloads, Apple will need to pay corresponding fees for subsequent downloads. Apple is actively communicating with Tencent,

DeepSeek: A powerful AI image generation tool! DeepSeek itself is not an image generation tool, but its powerful core technology provides underlying support for many AI painting tools. Want to know how to use DeepSeek to generate images indirectly? Please continue reading! Generate images with DeepSeek-based AI tools: The following steps will guide you to use these tools: Launch the AI Painting Tool: Search and open a DeepSeek-based AI Painting Tool (for example, search "Simple AI"). Select the drawing mode: select "AI Drawing" or similar function, and select the image type according to your needs, such as "Anime Avatar", "Landscape"

Rumors of WeChat supporting iPhone 16 were debunked. Thanks to netizens Xi Chuang Jiu Shi and HH_KK for submitting clues! According to news on September 2, there are rumors today that WeChat may not support iPhone 16. Once the iPhone is upgraded to the iOS 18.2 system, it will not be able to use WeChat. According to "Daily Economic News", it was learned from people familiar with the matter that this rumor is a rumor. Apple's response: According to Shell Finance, Apple's technical consultant in China responded that the issue of whether WeChat can continue to be used on iOS systems or Apple devices, and whether WeChat can continue to be listed and downloaded in the Apple App Store, needs to be resolved between Apple and Tencent. Only through communication and discussion can we determine the future situation. Currently, Apple is actively communicating with Tencent to confirm whether Tencent will continue to

Gate.io, a leading cryptocurrency trading platform founded in 2013, provides Chinese users with a complete official Chinese website. The website provides a wide range of services, including spot trading, futures trading and lending, and provides special features such as Chinese interface, rich resources and community support.

Gateio Exchange app download channels for old versions, covering official, third-party application markets, forum communities and other channels. It also provides download precautions to help you easily obtain old versions and solve the problems of discomfort in using new versions or device compatibility.

Gate.io (Sesame Open Door) is the world's leading cryptocurrency trading platform. This article provides a complete tutorial on spot trading of Gate.io. The tutorial covers steps such as account registration and login, KYC certification, fiat currency and digital currency recharge, trading pair selection, limit/market transaction orders, and orders and transaction records viewing, helping you quickly get started on the Gate.io platform for cryptocurrency trading. Whether a beginner or a veteran, you can benefit from this tutorial and easily master the Gate.io trading skills.

This article provides a detailed guide to safe download of Ouyi OKX App in China. Due to restrictions on domestic app stores, users are advised to download the App through the official website of Ouyi OKX, or use the QR code provided by the official website to scan and download. During the download process, be sure to verify the official website address, check the application permissions, perform a security scan after installation, and enable two-factor verification. During use, please abide by local laws and regulations, use a safe network environment, protect account security, be vigilant against fraud, and invest rationally. This article is for reference only and does not constitute investment advice. Digital asset transactions are at your own risk.

For investors new to the cryptocurrency world, it is crucial to understand how to buy virtual coins. This article is designed to provide a comprehensive guide to beginners covering detailed steps on how to choose the right exchange, register an account, deposit funds, and purchase Ethereum (ETH). By following this guide, beginners can safely and conveniently embark on their virtual currency investment journey and seize potential investment opportunities in 2025 and beyond.
