业务请求参数的集合,最大长度不限,除公共参数外所有请求参数都必须放在这个参数中传递,具体参照各产品快速接入文档
{
"code":0,
"msg":"订单创建成功",
"data":{
"mch_id":"10000",
"sub_mch_id":"",
"order_no":"T100001809271535453396",
"channel_order_no":"T000180925142202524",
"mch_order_no":"35471538033744",
"price":"0.01",
"total_fee":"0.01",
"pay_url":"{host}/transfer_pay.html?order_no=TtRSRyHzu7WEU1Gs21bS%2BezHDbSYXV9VZP5NOTes4ehDdYgaEObn54XmlRKjNS%2FNaoOky6HGdoNyQjl19wt%2Bcp7pqooqywyMkc%2BD5B7z383memnYv1FE4jtbn6rKbJwifWzDgkxvPEzjVQwJzP8W1YASoyWgCSPWNDbW%2FUseltE%3D",
"rate":"0.0100",
"service_charge":0,
"expire_time":1538034345
}
}
{
"code": -1,
"msg": "[100004] APP服务不在线",
"data": {}
}
// 请求操作
public function agentsRequest()
{
$mch_id = 10000; // 商户ID
$sub_mch_id = 100001; // 子商户号
// 请求内容
$content = [
'sub_mch_id' => $sub_mch_id,
'sub_mch_key' => 'e65f79cf10fb34216477de549d0d57a8',
'total_fee' => 200,
'order_sn' => date('YmdHis', time()),
'goods' => '代付商品00009',
'pay_type' => 1,
'user_id' => 1,
'notify_url' => 'http://newpay.frp.tinywan.top/index/demo_test/transferNotify',
'return_url' => 'http://newpay.frp.tinywan.top/index/demo_test/transferNotify',
];
// 请求数据
$data = [
'mch_id' => $mch_id,
'sub_mch_id' => $sub_mch_id,
'method' => 'shop.transfer.pay',
'version' => '1.0',
'timestamp' => time(),
'content' => json_encode($content)
];
// 签名 该方法请详见官方 SDK文档 【接口签名处理】->【生成签名】sign()
$sign = $this->sign($data, $mch_id);
Log::debug('[客户端] 签名字符串' . $sign);
if (!$sign) {
return ['success' => false, 'message' => '签名失败', 'code' => -1, 'data' => []];
}
$data['sign'] = $sign;
// 将所有参数urlcode编码,防止中文乱码
foreach ($data as &$item) {
$item = urlencode($item);
}
unset($item);
$url = 'https://pay.hongnaga.com/api/v1/gateway.do';
// 发起接口请求
$curl = curl_init();
curl_setopt($curl, CURLOPT_TIMEOUT, 60);
//设置抓取的url
curl_setopt($curl, CURLOPT_URL, $url);
//设置头文件的信息作为数据流输出
curl_setopt($curl, CURLOPT_HEADER, 0);
//设置获取的信息以文件流的形式返回,而不是直接输出。
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
//设置post方式提交
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_HTTPHEADER, array("Expect:"));
//设置post数据
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
//执行命令
$result = curl_exec($curl);
//关闭URL请求
curl_close($curl);
return $result;
}
// 签名方法
private function sign($data, $mch_id)
{
// 参数解码
foreach ($data as $key => &$value) {
$value = urldecode($value);
}
unset($value);
// 过滤掉无效的参数
if (isset($data['sign'])) {
unset($data['sign']);
}
// 商户秘钥key,可以通过商户管理平台【商户管理】=》【商户资料】
$key = "4845c24ee71e78f8e394afae1ce4bc36";
ksort($data);
$params_str = urldecode(http_build_query($data));
$params_str = $params_str . '&key=' . $key;
return md5($params_str);
}