微信h5支付(php版) 2019

2021-09-25 08:10:41 字數 3621 閱讀 5744

1.  登入商戶平台-->產品中心-->我的產品-->支付產品-->h5支付(申請開通),

2. 直接上**,乙個php即可搞定,本**適用於tp5開發,其他框架或語言需要自行修改

<?php 

use curl\curl;

use think\controller;

use think\request;

class wxpay extends controller

//支付成功通知位址

public function index()}}

/*** 下單方法

* @param $params 下單引數

*/public function unifiedorder()}'; //場景資訊,h5固定

$params['spbill_create_ip'] = $this->getip(); //終端ip

$params['mch_id'] = $this->mch_id;

$params['nonce_str'] = $this->genrandomstring(); //隨機字串

$params['notify_url'] = $this->notify_url; //通知位址

//獲取簽名資料

$params['sign'] = $this->makesign( $params ); //簽名

$xml = $this->data_to_xml($params);

$uri = ''; //請求位址

if( !$response )

$result = $this->xml_to_data( $response );

if( !empty($result['result_code']) && !empty($result['err_code']) )

if($result['result_code'] == 'success' && $result['return_msg'] == 'ok')

//return $result;

}/**

* 查詢訂單資訊

* @param $out_trade_no 訂單號

* @return array

*/public function orderquery( $out_trade_no )

$result = $this->xml_to_data( $response );

if( !empty($result['result_code']) && !empty($result['err_code']) )

return $result;

}/**

* 關閉訂單

* @param $out_trade_no 訂單號

* @return array

*/public function closeorder( $out_trade_no )

$result = $this->xml_to_data( $response );

return $result;

}/**

** 獲取支付結果通知資料

* return array

*/public function getnotifydata()

$data = $this->xml_to_data( $xml );

if( !empty($data['return_code']) )

}return $data;

}/**

* 接收通知成功後應答輸出xml資料

* @param string $xml

*/public function replynotify()

/*** @param $prepayid 預支付id

*/$data['partnerid'] = $this->mch_id;

$data['prepayid'] = $prepayid;

$data['package'] = 'sign=wxpay';

$data['noncestr'] = $this->genrandomstring();

$data['timestamp'] = time();

$data['sign'] = $this->makesign( $data );

return $data;

}/**

* 生成簽名

* @return 簽名

*/public function makesign( $params )

/*** 將引數拼接為url: key=value&key=value

* @param $params

* @return string

*/public function tourlparams( $params )

$string = implode("&",$array);

}return $string;

}/**

* 輸出xml字元

* @param $params 引數名稱

* return string 返回組裝的xml

**/public function data_to_xml( $params )

$xml = "";

foreach ($params as $key=>$val)

else

}$xml.="";

return $xml;

}/**

* 將xml轉為array

* @param string $xml

* return array

*/public function xml_to_data($xml)

//將xml轉為array

//禁止引用外部xml實體

libxml_disable_entity_loader(true);

$data = json_decode(json_encode(******xml_load_string($xml, '******xmlelement', libxml_nocdata)), true);

return $data;

}/**

* 獲取毫秒級別的時間戳

*/public static function getmillisecond()

/*** 產生乙個指定長度的隨機字串,並返回給使用者

* @param type $len 產生字串的長度

* @return string 隨機字串

*/public function genrandomstring($len = 32)

return $output;

}/**

* 錯誤**

* @param $code 伺服器輸出的錯誤**

* return string

*/public function error_code( $code )

}//xml請求

public function postxmlcurl($url,$xml,$second = 30)else

}//獲取使用者真實ip,此處為tp5所用,其他自行修改

public function getip()

}

4.開發不易,有用打賞一下,嘿嘿。

PHP微信H5支付

headers array 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 u...

php微信h5支付

1.預下單 public function getcode info elseif result result code fail else 2.前端付款頁面 doctype html html lang en head meta charset utf 8 title title style ty...

微信h5支付

首先需要檢視文件 知道h5支付的步驟 1.前台頁面 h5充值 2.後台介面直接呼叫統一下單 if stringutils.isnotblank ver str string passback order.containskey passback order.get passback string m...