1.以余额接口来举例子,当时测试使用的是http请求,后来正式上线之后不好用,我就用了curl
//获取富友余额开始
$user_name = $_SESSION['user_name'] ? $_SESSION['user_name'] : '';
//0001000F0394632
//0001000F0096241
$mchnt_cd= '0001000F0394632';
$mchnt_txn_ssn = date('ymd').substr(time(),-5).substr(microtime(),2,5);
$mchnt_txn_dt=date("Ymd");
$cust_no= $user_name;
$data =$cust_no."|".$mchnt_cd."|".$mchnt_txn_dt."|".$mchnt_txn_ssn;
$private_key_path = "../modules/php_prkey.pem";
$signature = rsaSign($data, $private_key_path);
function rsaSign($data, $private_key_path) {
$priKey = file_get_contents($private_key_path);
$res = openssl_get_privatekey($priKey);
openssl_sign($data, $sign, $res);
openssl_free_key($res);
//base64编码
$sign = base64_encode($sign);
return $sign;
}
//include_once('HttpClient.class.php');
//目标主机的地址,我这里填上测试的地址
//$Client = new HttpClient("https://jzh-test.fuiou.com/jzh/BalanceAction.action");
//https://jzh-test.fuiou.com/jzh/BalanceAction.action
//https://jzh.fuiou.com/BalanceAction.action
// $url = "https://jzh-test.fuiou.com/jzh/BalanceAction.action";//请求的页面地址
//$url = "https://jzh.fuiou.com/BalanceAction.action";//请求的页面地址
//POST的参数
$request_name="BalanceAction.action";
$param = array('mchnt_txn_ssn'=>$mchnt_txn_ssn,'mchnt_cd'=>$mchnt_cd,'mchnt_txn_dt'=>$mchnt_txn_dt,'cust_no'=>$cust_no,);
$param['signature']=$signature;
$result=curlPostdata($param,$request_name);
function curlPostdata($param,$request_name){
$url='https://jzh.fuiou.com/BalanceAction.action';
$postFields = http_build_query($param);
// $postField2=htmlspecialchars($postFields1);
// $postFields = html_entity_decode($postField2);
$postFields=str_replace("amp;", "", $postFields); //当时手机端请求富友老是报错,后来查询订单号才知道是拼接字符串的时候多出来“amp;”,所以这样解决,而pc端就没有这种问题,把问题附图放在下面
$ch = curl_init ();
curl_setopt ( $ch, CURLOPT_POST, 1 );
curl_setopt ( $ch, CURLOPT_HEADER, 0 );
curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt ( $ch, CURLOPT_URL, $url );
curl_setopt ( $ch, CURLOPT_POSTFIELDS, $postFields );
$result = curl_exec ( $ch );
echo $result;
curl_close ( $ch );
return $result;
}
//获取余额结束