濮阳杆衣贸易有限公司

主頁(yè) > 知識(shí)庫(kù) > php微信掃碼支付 php公眾號(hào)支付

php微信掃碼支付 php公眾號(hào)支付

熱門標(biāo)簽:阿里云400電話申請(qǐng)加工單 抖音有個(gè)地圖標(biāo)注是什么意思 西區(qū)企業(yè)怎么做地圖標(biāo)注入駐 保定crm外呼系統(tǒng)運(yùn)營(yíng)商 智能電話機(jī)器人排名前十名南京 九江外呼系統(tǒng) 地下城堡2圖九地圖標(biāo)注 海南人工外呼系統(tǒng)有效果嗎 七魚外呼系統(tǒng)停用嗎

本文實(shí)例為大家分享了php微信掃碼支付,公眾號(hào)支付的具體代碼,供大家參考,具體內(nèi)容如下

?php
 
# 微信統(tǒng)一下單接口
$url = 'https://api.mch.weixin.qq.com/pay/unifiedorder';
 
 
$param = [
 'appid' => '公眾號(hào)id',
 'mch_id' => '商戶id',
 'nonce_str' =>uniqid(),
 'sign_type' => 'MD5',
 'body' => 'test',
 'detail' => 'test detail',
 'out_trade_no' => date('Ymd').rand(10000,99999),
 'total_fee' => 1,
 'notify_url' => 'http://www.test.top/testpay/pay.php',
 'trade_type' =>'JSAPI',
];
 
 
ksort( $param );
 
$sign_str = urldecode(http_build_query( $param ));
 
 
$sign_str .= 'key=商戶密鑰';
 
 
//echo $sign_str;exit;
 
$sign_str = md5( $sign_str );
 
 
$param['sign'] = strtoupper( $sign_str );
 
function CurlPost($url, $param = [], $is_post = 1, $timeout = 5 )
{
 
 //初始化curl
 $curl = curl_init();
 
 // 設(shè)置請(qǐng)求的路徑
 curl_setopt($curl, CURLOPT_URL, $url);
 
 if ($is_post == 1) {
  //設(shè)置POST提交
  curl_setopt($curl, CURLOPT_POST, 0);
 }
 
 //顯示輸出結(jié)果 1代表 把接口返回的結(jié)果當(dāng)作一個(gè)字符串處理
 curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
 
 // 設(shè)置請(qǐng)求超時(shí)時(shí)間
 curl_setopt($curl, CURLOPT_TIMEOUT, $timeout);
 
 curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
 curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
 
 
 if ($is_post == 1) {
  //提交數(shù)據(jù) -- 設(shè)置post提交的數(shù)據(jù)
  if (is_array($param)) {
 
   //http_build_query
   curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($param));
  } else {
   curl_setopt($curl, CURLOPT_POSTFIELDS, $param);
  }
 }
 
 //執(zhí)行請(qǐng)求
 $data = $data_str = curl_exec($curl);
 //處理錯(cuò)誤
 if ($error = curl_error($curl)) {
  $log_data = array(
   'url' => $url,
   'param' => $param,
   'error' => 'span style="color:red;font-weight: bold">' . $error . '/span>',
  );
 
  var_dump($log_data);
  exit;
 }
 
 # 關(guān)閉CURL
 curl_close($curl);
 
 
 //json數(shù)據(jù)轉(zhuǎn)換為數(shù)組
 $data = json_decode($data, true);
 
 if (!is_array($data)) {
  $data = $data_str;
 }
 
 #調(diào)用玩接口之后寫一個(gè)日志
 $log = [
  'url' => $url,
  'param' => $param,
  'response' => $data_str
 ];
 file_put_contents(__DIR__ . '/wechat.log', print_r($log, true), 8);
 
 return $data;
 
}
function arr2Xml( $arr ){
 
 $xml = 'xml version="1.0" encoding="UTF-8"> ';
 foreach( $arr as $key => $value ){
  if (is_numeric($value)){
   $xml.="".$key.">".$value."/".$key.">";
  }else{
   $xml.="".$key.">![CDATA[".$value."]]>/".$key.">";
  }
 
 }
 $xml .= '/xml>';
 return $xml;
}
 
$xml = arr2Xml( $param );
 
$result = CurlPost( $url , arr2Xml($param) );
 
 
$api_arr = json_decode( json_encode(simplexml_load_string( $result , 'SimpleXMLElement', LIBXML_NOCDATA) ), true );
 
if( $api_arr['return_code'] == 'SUCCESS' ){
 
 include __DIR__ . '/phpqrcode.php';
 header('content-type:image/png');
 echo Qrcode::png( $api_arr['code_url'] , false , 'H' , 6 ,2 );
}
?php
 
#微信統(tǒng)一下單接口
$url='https://api.mch.weixin.qq.com/pay/unifiedorder';
 
$param=[
 #公眾賬號(hào)ID
 'appid'=>'****',
 'mch_id'=>'***',
 'nonce_str'=>uniqid(),
 'sign_type'=>'MD5',
 'body'=>'test',
 'detail'=>'detail',
 'out_trade_no'=>date('Ymd').rand(10000,99999),
 'total_fee'=>1,
 'spbill_create_ip'=>$_SERVER['SERVER_ADDR'],
 'notify_url'=>'http://****/test.php',
 'trade_type'=>'NATIVE',
];
ksort($param);
 
$sign_str=urldecode(http_build_query($param));
 
$sign_str.='key=8934e7d15453e97507ef794cf7b0519d';
 
$sign_str=md5($sign_str);
 
$param['sign']=strtoupper($sign_str);
 
//print_r($param);exit;
function CurlPost($url, $param = [], $is_post = 1, $timeout = 5 )
{
 //初始化curl
 $curl = curl_init();
 
 // 設(shè)置請(qǐng)求的路徑
 curl_setopt($curl, CURLOPT_URL, $url);
 
 if ($is_post == 1) {
  //設(shè)置POST提交
  curl_setopt($curl, CURLOPT_POST, 0);
 }
 
 //顯示輸出結(jié)果 1代表 把接口返回的結(jié)果當(dāng)作一個(gè)字符串處理
 curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
 
 // 設(shè)置請(qǐng)求超時(shí)時(shí)間
 curl_setopt($curl, CURLOPT_TIMEOUT, $timeout);
 
 curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
 curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
 
 
 if ($is_post == 1) {
  //提交數(shù)據(jù) -- 設(shè)置post提交的數(shù)據(jù)
  if (is_array($param)) {
 
   //http_build_query
   curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($param));
  } else {
   curl_setopt($curl, CURLOPT_POSTFIELDS, $param);
  }
 }
 
 //執(zhí)行請(qǐng)求
 $data = $data_str = curl_exec($curl);
 //處理錯(cuò)誤
 if ($error = curl_error($curl)) {
  $log_data = array(
   'url' => $url,
   'param' => $param,
   'error' => 'span style="color:red;font-weight: bold">' . $error . '/span>',
  );
 
  var_dump($log_data);
  exit;
 }
 
 # 關(guān)閉CURL
 curl_close($curl);
 
 
 //json數(shù)據(jù)轉(zhuǎn)換為數(shù)組
 $data = json_decode($data, true);
 
 if (!is_array($data)) {
  $data = $data_str;
 }
 
 #調(diào)用玩接口之后寫一個(gè)日志
 $log = [
  'url' => $url,
  'param' => $param,
  'response' => $data_str
 ];
 file_put_contents(__DIR__ . '/wechat.log', print_r($log, true), 8);
 
 return $data;
 
}
 
function arrzxml($arr){
 $xml='xml version="1.0" encoding="UTF-8">';
 foreach($arr as $key=>$value){
  if(is_numeric($value)){
   $xml.="".$key.">".$value."/".$key.">";
  }else{
   $xml.="".$key.">![CDATA[".$value."]]>/".$key.">";
  }
 
 }
 $xml.='/xml>';
// var_dump($xml);exit;
 return $xml;
 
}
 
$xml=arrzxml($param);
$result=CurlPost($url,arrzxml($param));
//echo 'pre/>';
var_dump($result);
exit;
$api_arr=json_decode(simplexml_load_string($result,'SimpleXMLElement',LIBXML_NOCDATA),true);
if($result['return_code']=='SUCCESS'){
 include __DIR__.'/phpqrcode.php';
 header('content-type:image/png');
 echo Qrcode::png($api_arr['code_url'],false,'H',6,2);
 
}

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

您可能感興趣的文章:
  • PC端微信掃碼支付成功之后自動(dòng)跳轉(zhuǎn)php版代碼
  • php實(shí)現(xiàn)微信掃碼支付
  • PHP 接入微信掃碼支付總結(jié)(總結(jié)篇)
  • PHP 微信掃碼支付源代碼(推薦)
  • php實(shí)現(xiàn)微信掃碼自動(dòng)登陸與注冊(cè)功能
  • thinkphp5實(shí)現(xiàn)微信掃碼支付

標(biāo)簽:九江 甘肅 涼山 十堰 遼陽(yáng) 昭通 梅河口 韶關(guān)

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《php微信掃碼支付 php公眾號(hào)支付》,本文關(guān)鍵詞  php,微信,掃碼,支付,公眾,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《php微信掃碼支付 php公眾號(hào)支付》相關(guān)的同類信息!
  • 本頁(yè)收集關(guān)于php微信掃碼支付 php公眾號(hào)支付的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    油尖旺区| 皋兰县| 墨江| 鹤山市| 孝感市| 姚安县| 临朐县| 铁岭县| 西城区| 平武县| 随州市| 五大连池市| 读书| 聂荣县| 即墨市| 台湾省| 永泰县| 西畴县| 青铜峡市| 宜昌市| 怀安县| 南和县| 阿尔山市| 东阿县| 海淀区| 河津市| 龙海市| 旌德县| 乳源| 仁布县| 石景山区| 水富县| 年辖:市辖区| 八宿县| 蒙自县| 赣州市| 河间市| 鸡西市| 宾阳县| 南丰县| 上高县|