程序員談如何對接微信H5支付(UI設計師怎么和程序員對接)

2024-02-13    分類: 網(wǎng)站建設

微信支付已經(jīng)變得越來越普遍,尤其是小程序,微網(wǎng)頁,基本微信支付是標配,大家都知道微信支付簡單使用,但是對于一個網(wǎng)站開發(fā)人員,如何配置和對接微信支付呢?

下面創(chuàng)新互聯(lián)技術人員為你簡單介紹
手機網(wǎng)站在非微信的瀏覽器中打開,需要用到微信H5支付
第一步:登錄商戶平臺,在 產(chǎn)品中心>產(chǎn)品大全>我的產(chǎn)品>H5支付 點擊“申請開通” 



第二步:填寫支付域名
提交審核一般會在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 框架的自帶函數(shù),會報“網(wǎng)絡環(huán)境未能通過安全驗證,請稍后再試”因為商戶側統(tǒng)一下單傳的終端IP(spbill_create_ip)與用戶實際調(diào)起支付時微信側檢測到的終端IP不一致導致的,一般是商戶在統(tǒng)一下單時沒有傳遞正確的終端IP到spbill_create_ip導致,我們要修改一下這個函數(shù):
/*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'; //回調(diào)地址
  $trade_type = 'MWEB';//交易類型 具體看API 里面有詳細介紹
  $body="H5支付";
$scene_info ='{"h5_info":{"type":"Wap","wap_url":"https://www.szfangwei.cn/","wap_name":"支付"}}';//場景信息 必要參數(shù)
$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"; //拼接字符串  注意順序微信有個測試網(wǎng)址 順序按照他的來 直接點下面的校正測試 包括下面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 轉換成數(shù)組


以上就是關于程序員談如何對接微信H5支付(UI設計師怎么和程序員對接),希望對你有幫助,更多內(nèi)容關注創(chuàng)新互聯(lián)。

新聞名稱:程序員談如何對接微信H5支付(UI設計師怎么和程序員對接)
本文網(wǎng)址:http://www.muchs.cn/news47/317297.html

成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站導航、手機網(wǎng)站建設、微信小程序、營銷型網(wǎng)站建設、響應式網(wǎng)站、服務器托管

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉載內(nèi)容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)

成都seo排名網(wǎng)站優(yōu)化