当前位置:网站首页>Wechat H5 payment on WAP, for non wechat browsers
Wechat H5 payment on WAP, for non wechat browsers
2022-07-26 09:47:00 【Color the sky】
When I was working on a project wap Wechat payment is realized on the end , I heard from my friends that wechat has wap Terminal h5 payment , Just look at this interface , Record it for future reference
( For the specific interface, you can check the merchant platform description :https://pay.weixin.qq.com/wiki/doc/api/H5.php?chapter=15_1)
<?php /** * Non wechat browser Call wechat h5 payment */ namespace app\mobile\controller; use think\Controller; use think\Loader; use think\Request; use think\Url; use think\Config; use think\Page; class Wxpay extends MobileBase { /** * @return array Order method */ public function wxpaymoney(Request $request) { $param=$request->param(); if (!empty($param)){ $param = json_decode(json_encode(simplexml_load_string($param, 'SimpleXMLElement', LIBXML_NOCDATA)), true); echo '-------'; p($param); echo '*******'; } $url='https://api.mch.weixin.qq.com/pay/unifiedorder'; // Place of order $appid='appid';// official account appid $appsecret='appsecret'; $mch_id=' Merchant platform id';// Merchant platform id $nonce_str='qyzf'.rand(100000, 999999);// random number $out_trade_no='wap'.date('YmdHis').rand(100000,999999); $ip=$this->getClientIp(); $scene_info='{"h5_info": {"type":"Wap","app_name": "project info","package_name": "wap Order wechat payment "}}'; // $appidInfo=$this->getTokens($appid,$appsecret); // echo '======='; // p($appidInfo); // echo '*******';die; // $openid=$appidInfo['openid']; $total_fee=1; $trade_type='MWEB'; $attach='wap Payment test '; $body='H5 Payment test '; $notify_url='http://m.xxxxx.com/Mobile/Wxpay/wxnotify.html'; $arr=[ 'appid'=>$appid, 'mch_id'=>$mch_id, 'nonce_str'=>$nonce_str, 'out_trade_no'=>$out_trade_no, 'spbill_create_ip'=>$ip, 'scene_info'=>$scene_info, // 'openid'=>$openid, 'total_fee'=>$total_fee, 'trade_type'=>$trade_type, 'attach'=>$attach, 'body'=>$body, 'notify_url'=>$notify_url ]; $sign=$this->getSign($arr); //<openid>'.$openid.'</openid> $data='<xml> <appid>'.$appid.'</appid> <attach>'.$attach.'</attach> <body>'.$body.'</body> <mch_id>'.$mch_id.'</mch_id> <nonce_str>'.$nonce_str.'</nonce_str> <notify_url>'.$notify_url.'</notify_url> <out_trade_no>'.$out_trade_no.'</out_trade_no> <spbill_create_ip>'.$ip.'</spbill_create_ip> <total_fee>'.$total_fee.'</total_fee> <trade_type>'.$trade_type.'</trade_type> <scene_info>'.$scene_info.'</scene_info> <sign>'.$sign.'</sign> </xml>'; $result=$this->https_request($url,$data); echo '===================='; var_dump($result); echo '*******************'; // Prohibit external references xml Entity libxml_disable_entity_loader(true); $result_info = json_decode(json_encode(simplexml_load_string($result, 'SimpleXMLElement', LIBXML_NOCDATA)), true); p($result_info); echo '<a href="'.$result_info['mweb_url'].'"> Test wechat payment </a>';die; } /** *curl request */ private function https_request($url, $data = null) { p($data); $curl = curl_init (); curl_setopt ( $curl, CURLOPT_URL, $url ); curl_setopt ( $curl, CURLOPT_SSL_VERIFYPEER, FALSE ); curl_setopt ( $curl, CURLOPT_SSL_VERIFYHOST, FALSE ); if (! empty ( $data )) { curl_setopt ( $curl, CURLOPT_POST, 1 ); curl_setopt ( $curl, CURLOPT_POSTFIELDS, $data ); } curl_setopt ( $curl, CURLOPT_RETURNTRANSFER, 1 ); $output = curl_exec ( $curl ); curl_close ( $curl ); return $output; } /** * @return obtain ip */ private function getClientIp() { $cip='unknown'; if ($_SERVER['REMOTE_ADDR']){ $cip=$_SERVER['REMOTE_ADDR']; }elseif (getenv($_SERVER['REMOTE_ADDR'])){ $cip=getenv($_SERVER['REMOTE_ADDR']); } return $cip; } /** * @return Asynchronous notification */ public function wxnotify(Request $request) { Loader::import('payment.wxwap.PayNotifyCallBacks'); $notify=new \PayNotifyCallBacks(); $notify->Handle(false); die; } /** * @param Request */ public function wxcallback(Request $request) { $data=$request->param(); file_put_contents('./testwx1.txt','888888888888888'.$data['orderid'].'-----'.$data['transaction_id'].'******'); } /** * effect : Format parameters , The signature process needs to use */ public function formatBizQueryParaMap($paraMap, $urlencode) { // var_dump($paraMap);//die; $buff = ""; ksort($paraMap); foreach ($paraMap as $k => $v) { if($urlencode) { $v = urlencode($v); } //$buff .= strtolower($k) . "=" . $v . "&"; $buff .= $k . "=" . $v . "&"; } $reqPar=''; if (strlen($buff) > 0) { $reqPar = substr($buff, 0, strlen($buff)-1); } p($reqPar);//die; return $reqPar; } /** * effect : Generate signature */ public function getSign($Obj) { p($Obj);//die; foreach ($Obj as $k => $v) { $Parameters[$k] = $v; } // Signature step 1 : Sort parameters in dictionary order ksort($Parameters); $String = $this->formatBizQueryParaMap($Parameters, false); //echo '【string1】'.$String.'</br>'; // Signature step 2 : stay string Then add KEY 5a02bd8ecxxxxxxxxxxxxc1aae7d199 The secret key here is The merchant platform settings must be changed, otherwise the signature error will be reported $String = $String."&key=5a02bd8ecxxxxxxxxxxxxc1aae7d199"; //echo "【string2】".$String."</br>"; // Signature step 3 :MD5 encryption $String = md5($String); //echo "【string3】 ".$String."</br>"; // Signature step 4 : All characters are capitalized $result_ = strtoupper($String); //echo "【result】 ".$result_."</br>"; return $result_; } private function httpGet($url) { $curl = curl_init(); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_TIMEOUT, 500); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($curl, CURLOPT_URL, $url); $res = curl_exec($curl); curl_close($curl); return $res; } }
test demo(PHP edition ): http://download.csdn.net/download/u010533511/10155017
边栏推荐
- Interview shock 68: why does TCP need three handshakes?
- 在Blazor 中自定义权限验证
- JS判断数据类型 Object.prototype.toString.call和typeof
- [MySQL] understand the important architecture of MySQL (I)
- Mo team learning notes (I)
- spolicy请求案例
- 编写一个在bash / shell 和 PowerShell中均可运行的脚本
- Gauss elimination solves the inverse of matrix (Gauss)
- 网络流学习笔记
- (二)面扫描仪与机械臂的手眼标定(眼在手外:九点标定)
猜你喜欢

解决ProxyError: Conda cannot proceed due to an error in your proxy configuration.

Great reward for interview questions

解决npm -v突然失效 无反应

Fiddler packet capturing tool for mobile packet capturing

Node 内存溢出及V8垃圾回收机制

服务器、客户端双认证(2)

MySQL的逻辑架构

Logical architecture of MySQL

Unstoppable, pure domestic PCs have been in place, and the monopoly of the U.S. software and hardware system has been officially broken

阿里云技术专家郝晨栋:云上可观测能力——问题的发现与定位实践
随机推荐
copyTo
Global variables in DLL
JS 连等赋值操作
【信息系统项目管理师】初见高项系列精华汇总
Gauss elimination for solving XOR linear equations
一种分布式深度学习编程新范式:Global Tensor
网站设计需要的基本知识
Sqoop【付诸实践 02】Sqoop1最新版 全库导入 + 数据过滤 + 字段类型支持 说明及举例代码(query参数及字段类型强制转换)
SSG framework Gatsby accesses the database and displays it on the page
asp. Net using redis cache (2)
莫队学习总结(二)
Why does new public chain Aptos meet market expectations?
Logical architecture of MySQL
After attaching to the process, the breakpoint displays "currently will not hit the breakpoint, and no symbols have been loaded for this document"
Great reward for interview questions
matlab simulink实现模糊pid对中央空调时延温度控制系统控制
antd TreeSelect获取父节点的值
Source code analysis of object wait notify notifyAll
解决npm -v突然失效 无反应
Flutter event distribution