PHP实现唤起微信支付功能
微信(小程序)  /  管理员 发布于 7年前   281
本文实例为大家分享了PHP唤起微信支付的具体代码,供大家参考,具体内容如下 以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。'****', //公众账号ID appid 是 String(32) wxd678efh567hg6787 微信分配的公众账号ID(企业号corpid即为此appId) 'mch_id'=>'****',// 商户号 mch_id 是 String(32) 1230000109 微信支付分配的商户号 'nonce_str'=>rand(100000,999999),// 随机字符串 nonce_str 是 String(32) 5K8264ILTKCH16CQ2502SI8ZNMTM67VS 随机字符串,不长于32位。推荐随机数生成算法 'key'=>'****', 'APPSECRET'=>'*****', ); return $array; } public function H5WeiXin(){ $config = $this->config(); $count=1; //$money= 1;//充值金额 $userip = $this->getIP(); //获得用户设备IP $appid = $config['appid']; $mch_id = $config['mch_id']; $key = $config['key']; $rand = rand(00000,99999); $out_trade_no = $_POST['number'];//订单号 $nonce_str=MD5($rand);//随机字符串 $body = $data['title'];//内容 $total_fee = $count; //金额 $spbill_create_ip = $userip; //IP $notify_url = 'http://'.$_SERVER['HTTP_HOST'].'/Wap/H5wx/WxHD'; //回调地址 $redirect_url = 'http://'.$_SERVER['HTTP_HOST'].'/Wap/H5wx/is_wxpay?number='.$_POST['number']; //回调地址 $trade_type = 'MWEB';//交易类型 $scene_info ='{"h5_info":{"type":"Wap","wap_url":"'.$_SERVER['HTTP_HOST'].'","wap_name":"'.$data['title'].'"}}';//场景信息 $signA ="appid=$appid&body=$body&mch_id=$mch_id&nonce_str=$nonce_str¬ify_url=$notify_url&out_trade_no=$out_trade_no&scene_info=$scene_info&spbill_create_ip=$spbill_create_ip&total_fee=$total_fee&trade_type=$trade_type"; $strSignTmp = $signA."&key=$key"; //拼接字符串 $sign = strtoupper(MD5($strSignTmp)); // MD5 后转换成大写 $post_data = "
未查询到此订单的付款信息
'; } } //微信回调地址 public function WxHD(){ $url = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING']; $array = $this->xmlToArray($GLOBALS['HTTP_RAW_POST_DATA']); M('api_log')->add(array('content'=>json_encode($this->xmlToArray($GLOBALS['HTTP_RAW_POST_DATA'])).$array['out_trade_no'])); if($array['return_code']=='SUCCESS'){ $out_trade_no=$array['out_trade_no']; //$number = explode('-',$out_trade_no); $type = substr($out_trade_no,0,1); header("location: http://".$_SERVER['HTTP_HOST'].$url.""); } }public function xmlToArray($xml){ //禁止引用外部xml实体 libxml_disable_entity_loader(true); $xmlstring = simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA); $val = json_decode(json_encode($xmlstring),true); return $val; } public function convertUrlQuery($query){ $queryParts = explode('&', $query); $params = array(); foreach ($queryParts as $param) { $item = explode('=', $param); $params[$item[0]] = $item[1]; } return implode('&',$params);} public function http_post($url, $data) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,$url); curl_setopt($ch, CURLOPT_HEADER,0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); $res = curl_exec($ch); curl_close($ch); return $res; } public function getIP() { if(getenv('HTTP_CLIENT_IP')) { $ip = getenv('HTTP_CLIENT_IP'); }elseif (getenv('HTTP_X_FORWARDED_FOR')) { $ip = getenv('HTTP_X_FORWARDED_FOR'); }elseif (getenv('HTTP_X_FORWARDED')) { $ip = getenv('HTTP_X_FORWARDED'); }elseif (getenv('HTTP_FORWARDED_FOR')) { $ip = getenv('HTTP_FORWARDED_FOR'); }elseif (getenv('HTTP_FORWARDED')) { $ip = getenv('HTTP_FORWARDED'); }else { $ip = $_SERVER['REMOTE_ADDR']; } return $ip; } } ?>您可能感兴趣的文章:
122 在
学历:一种延缓就业设计,生活需求下的权衡之选中评论 工作几年后,报名考研了,到现在还没认真学习备考,迷茫中。作为一名北漂互联网打工人..123 在
Clash for Windows作者删库跑路了,github已404中评论 按理说只要你在国内,所有的流量进出都在监控范围内,不管你怎么隐藏也没用,想搞你分..原梓番博客 在
在Laravel框架中使用模型Model分表最简单的方法中评论 好久好久都没看友情链接申请了,今天刚看,已经添加。..博主 在
佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 @1111老铁这个不行了,可以看看近期评论的其他文章..1111 在
佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 网站不能打开,博主百忙中能否发个APP下载链接,佛跳墙或极光..
Copyright·© 2019 侯体宗版权所有·
粤ICP备20027696号