惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Security Archives - TechRepublic
Security Archives - TechRepublic
N
News and Events Feed by Topic
Last Week in AI
Last Week in AI
博客园 - 司徒正美
The GitHub Blog
The GitHub Blog
O
OpenAI News
The Last Watchdog
The Last Watchdog
T
The Blog of Author Tim Ferriss
M
MIT News - Artificial intelligence
P
Proofpoint News Feed
Forbes - Security
Forbes - Security
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
有赞技术团队
有赞技术团队
Jina AI
Jina AI
GbyAI
GbyAI
V
Vulnerabilities – Threatpost
L
LangChain Blog
Vercel News
Vercel News
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
AI
AI
博客园 - 聂微东
W
WeLiveSecurity
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Scott Helme
Scott Helme
罗磊的独立博客
Martin Fowler
Martin Fowler
S
Security Affairs
T
Tor Project blog
Recent Announcements
Recent Announcements
F
Fortinet All Blogs
美团技术团队
C
Cisco Blogs
PCI Perspectives
PCI Perspectives
Recent Commits to openclaw:main
Recent Commits to openclaw:main
S
Security @ Cisco Blogs
T
Threat Research - Cisco Blogs
A
About on SuperTechFans
Cisco Talos Blog
Cisco Talos Blog
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
I
Intezer
B
Blog
WordPress大学
WordPress大学
I
InfoQ
G
Google Developers Blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
V
V2EX
P
Privacy & Cybersecurity Law Blog
雷峰网
雷峰网

博客园 - 代码小伙

gin框架使用zap,在日志中加入trace_id gorm使用gen自动生成模型和查询文件 Go使用base64Captcha生成字母验证码 GoFrame框架查询数据表时对字段取别名 GoFrame框架使用WherePri报错原因 GoFrame框架使用BindHandler设置路由失效的原因 GoFrame框架WebServer默认端口号是什么 GoFrame框架SetFileServerEnabled关闭静态服务不生效 vite修改端口号 用路由方式写一个通用的微信小程序校验文件验证 position:sticky失效原因分析 mysql把一个表的字段赋值到另一张表 基于jquery的countdown插件实现毫秒倒计时 Vue打包代码如何部署在ThinkPHP项目里 保姆级教程,centos7安装erlang和rabbitmq Element Plus表单resetFields重置表单无效 thinkphp6通过中间件设置跨域 centos7安装jdk vue3中使用swiper6实现轮播
手机网页通过微信deeplink实现wap支付
代码小伙 · 2023-10-19 · via 博客园 - 代码小伙

微信支付里目前已经不支持wap支付,在非微信浏览器手机网页中实现支付,可以开通H5支付。
H5支付是调用微信下单接口后返回微信的一个H5链接,前端跳转到这个H5链接,这个H5链接是个支付中间页,实现了和微信app通信,拉起微信支付,并回跳商户return_url的功能,而当用户返回时,会停留在这个支付中间页,会是空白,对于用户来说体验不好。
官方也不建议再用早期的wap支付,但实际我们可以通过下单接口获取的H5链接中提取出deeplink(实际支付中间页也是通过deeplink拉起的),直接在当前商户页面拉起微信支付,不需要通过支付中间页,返回时就不会出现空白,但也有不好的地方,是无法跳转到return_url
调用微信统一下单接口https://api.mch.weixin.qq.com/pay/unifiedorder(trade_type值为MWEB)后,向返回的mweb_url做一次CURL,通过正则匹配出deeplink,主要代码如下

  $ip = '获取当前客户端IP';
  $headers = array("X-FORWARDED-FOR:$ip", "CLIENT-IP:$ip");
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, $mweb_url);
  curl_setopt($ch, CURLOPT_HTTPHEADER , $headers);
  curl_setopt($ch, CURLOPT_REFERER, '填写配置在微信商户后台的H5域名');
  curl_setopt($ch, CURLOPT_HEADER, false);
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
  curl_setopt($ch, CURLOPT_TIMEOUT, 5);
  curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Linux; Android 6.0.1; OPPO R11s Build/MMB29M; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/55.0.2883.91 Mobile Safari/537.36');
  $output = curl_exec($ch);
  curl_close($ch);
  if (preg_match('/weixin:\/\/wap.*/',$output, $mweb_urls)) {
      return json(
          [
              "code" => 200,
              "data" => trim($mweb_urls[0],'"'),
              "message" => "SUCCESS"
          ]
      );
  } else {
      return json(
          [
              "code" => 400,
              "data" => "",
              "message" => "订单参数异常,请重新下单后再发起付款"
          ]
      );
  }