public function fzPay($receivers_arr)
{
//下单支付的时候"profit_sharing" => "Y" 把订单设置Y
$sub_appid = $app_id;
$sub_mch_id = $mchid;
$out_trade_no = makeOrderNo();
$nonce_str = getRandom(32);
$key = 'apikey';
$transaction_id = 'transaction_id';//微信返回的编号
//$receivers_arr 是分账类型具体看图片
$receivers = json_encode($receivers_arr);
$arr = [
'appid' => $sub_appid,
'transaction_id' => $transaction_id,
'mch_id' => $sub_mch_id,
'nonce_str' => $nonce_str,
'out_order_no' => $out_trade_no,
'receivers' => $receivers,
];
//签名步骤一:按字典序排序参数
ksort($arr);
$str = $this->to_url_params($arr);
//签名步骤二:在str后加入KEY
$str = $str."&key=".$key;
//签名步骤三:HMAC-SHA256 类型 加密的字符串 key是商户秘钥
$str = hash_hmac('sha256', $str, $key);
//签名步骤四:所有字符转为大写
$result = strtoupper($str);
$arr['sign'] = $result;
$xmlData = '<?xml version="1.0" encoding="UTF-8"?><xml>';
foreach ($arr as $key => $val) {
$xmlData .= "<".$key.">$val</".$key.">";
}
$xmlData .= "</xml>";
$url
= 'https://api.mch.weixin.qq.com/secapi/pay/profitsharing'; //接收xml数据的文件
$ch = curl_init();
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSLCERTTYPE, 'PEM');
curl_setopt(
$ch,
CURLOPT_SSLCERT,
'xx.pem'
);
curl_setopt($ch, CURLOPT_SSLKEYTYPE, 'PEM');
curl_setopt(
$ch,
CURLOPT_SSLKEY,
'xx.pem'
);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xmlData);
$result = curl_exec($ch);
curl_close($ch);
return $this->toXml($result);
}
07-03
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交