Payment interface and docking technology Quartet general method of third-party payment interface docking Development Guide API Integration Services

Payment interface docking technology to do more in the future you will find that virtually all of the basic method of third-party fourth-party payment process interface is such, as to some of the signature is not the same, not the same formulation parameters and so on in accordance with the requirements of the technical documentation it provides We can change it, do not understand can contact.

//配制类,填写在支付平台获取的相关信息
class Constant {
	const USER= "QQ4770851";
    const MERCHNO = "ff8080816586cbd434358a66b0bc1525";
    const CREATE_URL = "https://xxx.com/order/create";
    const QUERY_URL = "https://xxx.com/order/query";
    const KEY = "C66604323DFA42B4864299246E04FD1B";

}
//签名类,按照支付平台的规则对参数进行签名
class SignUtils {
    /** = */
    const QSTRING_EQUAL = "=";
    /** & */
    const QSTRING_SPLIT = "&";
    public static function signMD5($param, $merKey = '') {
    	ksort($param);

    	$arr = [];
    	foreach ($param as $key => $value) {
    		$arr[] = $key . self::QSTRING_EQUAL . $value;
    	}
    	$str = implode(self::QSTRING_SPLIT, $arr);
    	return strtoupper(md5($str . self::QSTRING_SPLIT . $merKey));
    }
}

//请求类,发起支付请求
class HttpUtils {
	/**
	 * [post description]
	 * @param  [type] $url  [description]
	 * @param  array  $post [description]
	 * @return [type]       [description]
	 */
	public static function post($url, $post = []) {
	    $headers = [ "Content-type: application/json;charset='utf-8'", "Accept: application/json", "Cache-Control: no-cache", "Pragma: no-cache" ];
		$ch = curl_init($url);
		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
		curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
		curl_setopt($ch, CURLOPT_TIMEOUT, 60);
		curl_setopt($ch, CURLOPT_POST, TRUE);
		curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($post));
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
		curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

		$data = curl_exec($ch);//CURLOPT_RETURNTRANSFER 不设置  curl_exec返回TRUE 设置  curl_exec返回json(此处) 失败都返回FALSE
		curl_close($ch);

	    return $data;
	}
}

// 支付正文开始,配制参数,发起请求
$param = [];
$param['merchno'] = Constant::MERCHNO;
$param['out_trade_no'] = $_POST['rechargeId'];
$param['subject'] = $_POST['username'];
$param['total_amount'] = $_POST['amount'];
$param['redirect_url'] = 'http://'.$_SERVER['HTTP_HOST'].'/return.php';
$param['notify_url'] = 'http://'.$_SERVER['HTTP_HOST'].'/notify.php';
$param['sign'] = SignUtils::signMD5($param, Constant::KEY);
$response = HttpUtils::post(Constant::CREATE_URL, $param);
$arr = json_decode($response,TRUE);
header("location:".$arr['pay_url']);

Guess you like

Origin blog.csdn.net/jeesr/article/details/90639283