(这篇文章默认支付接口是正确可用的)
在写项目的时候,客户要求做一个店铺扫码支付的功能,这个功能在支付宝上很容易实现,官网上集成了这个方法。
但是微信却不然,微信的这个功能实现需要程序员对于微信本身的公众号支付的接口进行二次开发。
开发的思路也很简单就是程序员这边做一个可以输入价格的界面,然后调用微信的公众号支付接口即可。
但是就这么简单的功能,我就卡了好几天。
出错的地方在于在线上微信内扫码打开上面的页面之后,点击表单提交,不论是get还是post都无法实现数据的正确传递。
基于我是一个从没有写过html页面的人,我一开始怀疑我的页面写的不对,我仔细检查完了之后,确定在除去线上微信内
的其他地方都是可以正确的得到预期的数据。
于是我就去问万能的度娘,得到的结果应该和大家的差不多,微信内post以及get传参有可能失败的,正当我准备骂娘的时候,
突然意识到,我们公司一直都在开发微信内的业务呀,也没发现有传参参不过来的问题呀。于是在稀里糊涂的搞了几天之后,我终
于发现了问题所在,吼吼!
对微信支付有一定了解的人都知道微信公众号支付即JSAPI支付需要去微信公众平台配置用户的支付权限目录,问题就出现在
这个支付目录,微信对于这个支付目录的限制很死,例如http://xxx/就是你设置的支付目录,那么你的支付接口代码写的路由至多
只能在设置好的支付目录下一层。不然都会报该路由没有支付权限。这只是其一,其二是进入支付目录的传参也会被微信保护,所
以get-post传的值会被微信取代或者拦截掉。
知道了上述的两点:那么解决方法也就很简单了,就是通过路由来传递参数,例如http://xxx/0-价格-备注,然后在后台的代
码中用 explode('-',变量名); 方法来对路由的最后部分进行字符串数组拆分,就可以在微信的规则下得到需要传递的参数了。
在这里我就不展示我php的代码了,因为里面都是公众号支付的代码,和此篇的文章内容不符合,我就冒昧的贴出我的html代码,
展示如何将参数放在路由上传递吧(其实也没什么)。
<html><head> <meta charset="UTF-8"> <title>微信扫码支付</title> <style> .hide{display: none;} </style></head><body><h1 id="微信扫码支付">微信扫码支付</h1> 数额:<input type="text" id = 'price' name="price" ></br> 备注:<input type="text" id = 'tradingReason' name= "tradingReason" ></br> <input class="hide" type="text" id = 'url' name= "url" value="{{ url }} "></br> <input type="submit" value="支付" onclick="sub(getValue('price'), getValue('tradingReason') , getValue('url'))"></body><script type="text/javascript"> /* * 模板套的时候单击事件中的跳转方法不要改变(不然值传不到后台)--对传送的价格要进行合法性的验证 * */ function getValue(id) { return document.getElementById(id).value; } function sub(price, tradingReason , url) { var str =url+'-'+price+'-'+tradingReason; self.location = str; }</script></html>
最后展示一下最终的劳动成果吧!
本文永久地址:http://blog.it985.com/16089.html
本文出自IT985博客 ,转载时请注明出处及相应链接。

The article explains that HTML tags are syntax markers used to define elements, while elements are complete units including tags and content. They work together to structure webpages.Character count: 159

The article discusses the roles of <head> and <body> tags in HTML, their impact on user experience, and SEO implications. Proper structuring enhances website functionality and search engine optimization.

The article discusses the differences between HTML tags , , , and , focusing on their semantic vs. presentational uses and their impact on SEO and accessibility.

Article discusses specifying character encoding in HTML, focusing on UTF-8. Main issue: ensuring correct display of text, preventing garbled characters, and enhancing SEO and accessibility.

The article discusses various HTML formatting tags used for structuring and styling web content, emphasizing their effects on text appearance and the importance of semantic tags for accessibility and SEO.

The article discusses the differences between HTML's 'id' and 'class' attributes, focusing on their uniqueness, purpose, CSS syntax, and specificity. It explains how their use impacts webpage styling and functionality, and provides best practices for

The article explains the HTML 'class' attribute's role in grouping elements for styling and JavaScript manipulation, contrasting it with the unique 'id' attribute.

Article discusses HTML list types: ordered (<ol>), unordered (<ul>), and description (<dl>). Focuses on creating and styling lists to enhance website design.


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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

SublimeText3 Chinese version
Chinese version, very easy to use

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.
