ottpay境外支付
作者:互联网
$price = $price * 100;
$merchant = config('wx.merchant');
$operator_id = config('wx.operator_id');
$app_id = config('wx.userAppid');
$url = config('wx.backurl');
$wechatOrder = [
'action' => 'MAPPPAY',
'version' => '1.1',
'merchant_id' => $merchant,
'data' => [
'order_id' => $sn,
'operator_id' => $operator_id,
'amount' => "$price",
'biz_type' => 'WECHATPAY',
'app_id' => $app_id,
'open_id' => $user['openid'],
'call_back_url' => $url,
],
];
//境外支付
$response = ottPay($wechatOrder);
$res = json_decode($response);
if ($res->rsp_code == 'SUCCESS') {
$signjm = strtoupper(json_decode($response, true)["md5"] . "90B2E01C5DD08EE9");
$keyjm = strtoupper(substr(md5($signjm), 8, 16));
$d = base64_decode(json_decode($response, true)["data"]);
$response = openssl_decrypt($d, 'AES-128-ECB', $keyjm, OPENSSL_RAW_DATA, false);
$result = json_decode($response);
$result->code = 0;
return $result;
} else {
$res->code = 1;
// $res = json_encode($res);
return $res;
}
function ottPay($data)
{
//签名
ksort($data);
ksort($data["data"]);
$newdata = $data["data"];
$str = "";
foreach ($newdata as $k => $v) {
if (is_array($v)) {
foreach ($v as $k1 => $v1) {
$str .= $v1;
}
} else {
$str .= $v;
}
}
$signs = md5($str);
$signs = strtoupper($signs);
// $wechatOrder['md5'] = $sign;
$sign = strtoupper($signs . "90B2E01C5DD08EE9");
$key = strtoupper(substr(md5($sign), 8, 16));
$ordata = json_encode($newdata);
// $iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length('AES-128-ECB'));
// $iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length('AES-128-ECB'));
// dump($iv);die;
$aes = openssl_encrypt($ordata, 'AES-128-ECB', $key, OPENSSL_RAW_DATA, false);
$basesign = base64_encode($aes);
$data["data"] = $basesign;
$data["md5"] = $signs;
$data = json_encode($data, JSON_UNESCAPED_UNICODE);
//调用支付
$url = 'https://frontapi.ottpay.com:443/process'; //接收xml数据的文件
$header[] = "Content-type: application/json;charset=utf-8"; //定义content-type为xml,注意是数组
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // 兼容本地没有指定curl.cainfo路径的错误
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$response = curl_exec($ch);
return $response;
}
标签:response,ch,ottpay,境外,json,支付,curl,data,id 来源: https://blog.csdn.net/weixin_43926608/article/details/112507179