J9国际集团|Home

135-2716-3909
网站建设资讯详细

程序员谈□□如何对接□□微信H5支付

发表日期:2026-06-17 11:46:38   作者来源:J9国际集团   浏览:6913   标签:H5网站建设    微信网站建设    
微信支付□□□已经变得□□□□越来越普□□□□遍,尤其是小□□程序,微网页,基本微信□□□□支付是标◎配,大家都知•道微信支□□□□付简单使□□□用,但是对于□□一个网站❖开发人员,如何配置◤和对接微□□信支付呢?
下面J9国际集团技术人员为你简单介绍

手机网站在非微信的浏览器中打开,需要用到微信H5支付
第一步:登录商户□□□平台,在 产品中心>产品大全>我的产品>H5支付 点击“申请开通” 
 

微信支付申请1

第二步:填写支付◤域名

微信支付域名配置

提交审核▲一般会在3-5个工作日。
$headers[] = 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8';  
  $headers[] = 'Connection: Keep-Alive';  
  $headers[] = 'Accept-Language: ru-RU,ru;q=0.8,en-US;q=0.5,en;q=0.3'; 
  $headers[] = 'Accept-Encoding: gzip, deflate'; 
  $headers[] = 'User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:22.0) Gecko/20100101 Firefox/22.0';
  $userip =$this->get_client_ip(); //获得用户□□□设备IP
  注意:这个Thinkphp 框架的自□□□带函数,会报“网络环境□□未能通过□□□□安全验证,请稍后再□□□试”因为商户◣侧统一下□□□□单传的终□□□□端IP(spbill_create_ip)与用户实□□际调起支□□□□付时微信□□□□侧检测到□□□□的终端IP不一致导□□□□致的,一般是商□□户在统一□□□下单时没◉有传递正□□□确的终端IP到spbill_create_ip导致,我们要修○改一下这□□□个函数:
/*function get_client_ip(){
    if(getenv('HTTP_CLIENT_IP') && strcasecmp(getenv('HTTP_CLIENT_IP'),'unknown')) {
 $ip = getenv('HTTP_CLIENT_IP');
    } elseif(getenv('HTTP_X_FORWARDED_FOR') && strcasecmp(getenv('HTTP_X_FORWARDED_FOR'),'unknown')) {
   $ip = getenv('HTTP_X_FORWARDED_FOR');
    } elseif(getenv('REMOTE_ADDR') && strcasecmp(getenv('REMOTE_ADDR'),'unknown')) {
    $ip = getenv('REMOTE_ADDR');
    } elseif(isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], 'unknown')) {
 $ip = $_SERVER['REMOTE_ADDR'];
    }
 return preg_match ( '/[\d\.]{7,15}/', $ip, $matches ) ? $matches [0] : '';
}
}*/
  $appid = "xxxxxxxxxxx";//微信
  $mch_id = "xxxxxxxxxxx";//微信官方的
  $key = "xxxxxxxxxxxxxxxxxxxxxxxxxxx";//自己设置□□□的微信商□□□□家key
  $nonce_str=MD5($order_no);//随机字符串
  //dump($orderArr['orderno']);
  $total_fee = $total*100; //微信金额□□是以分为□□单位
  $spbill_create_ip = $userip; //IP
  $notify_url = 'http://xxxxxxxxxxxxxxxxxxxxxx/wxnotify'; //回调地址
  $trade_type = 'MWEB';//交易类型 具体看API 里面有详□□□细介绍
  $body="H5支付";
$scene_info ='{"h5_info":{"type":"Wap","wap_url":"https://www.lyzhuzao.com/","wap_name":"支付"}}';//场景信息 必要参数
$signA ="appid=$appid&body=$body&mch_id=$mch_id&nonce_str=$nonce_str¬ify_url=$notify_url&out_trade_no=$order_no&scene_info=$scene_info&spbill_create_ip=$spbill_create_ip&total_fee=$total_fee&trade_type=$trade_type";
 
$strSignTmp = $signA."&key=$key"; //拼接字符□□□□串  注意顺序□□□微信有个◆测试网址 顺序按照□□□他的来 直接点下□□□面的校正▽测试 包括下面XML  是否正确
$sign = strtoupper(MD5($strSignTmp)); // MD5 后转换成◥大写
$post_data="$appid$body$mch_id$nonce_str$notify_url$order_no$scene_info$spbill_create_ip$total_fee$trade_type$sign
  ";//将拼接成XML 格式
  $url = "https://api.mch.weixin.qq.com/pay/unifiedorder";//微信传参地址
  $dataxml = $this->http_post($url,$post_data,$headers);
/* function http_post($url='',$post_data=array(),$header=array(),$timeout=30) {
 
  $ch = curl_init(); 
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // 跳过证书□□□□检查 
  curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);  // 从证书中❖检查SSL加密算法□□□□是否存在 
curl_setopt($ch, CURLOPT_URL, $url); 
  curl_setopt($ch, CURLOPT_HTTPHEADER, $header); 
  curl_setopt($ch, CURLOPT_POST, true); 
  curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); 
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);  
  curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); 
  $response = curl_exec($ch); 
  curl_close($ch);
  return $response;
  }   */
  header("content-type:text/html;charset=utf-8");
  $objectxml = (array)simplexml_load_string($dataxml,'SimpleXMLElement',LIBXML_NOCDATA); //将微信返◇回的XML 转换成数◢组
 

如没特殊注明,文章均为J9国际集团原创,转载请注明来自https://www.lyzhuzao.com/news/4814.html