新增物流回调
This commit is contained in:
parent
0f4a6629da
commit
ac382e288c
@ -535,8 +535,6 @@ class CallBackController extends AbstractController
|
|||||||
return $server->serve();
|
return $server->serve();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 微信支付返回错误响应
|
* 微信支付返回错误响应
|
||||||
* @param string $message
|
* @param string $message
|
||||||
@ -733,8 +731,87 @@ class CallBackController extends AbstractController
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 处方平台物流回调
|
// 处方平台物流回调
|
||||||
public function platformLogisticsCallBack(){
|
public function platformLogisticsCallBack(): ResponseInterface
|
||||||
|
{
|
||||||
|
$request_params = $this->request->all();
|
||||||
|
try {
|
||||||
|
Log::getInstance()->info("处方平台物流回调数据:" . json_encode($request_params,JSON_UNESCAPED_UNICODE));
|
||||||
|
|
||||||
|
if (!isset($request_params['sign']) ){
|
||||||
|
Log::getInstance()->error("处方平台物流回调数据处理失败:缺少签名结果");
|
||||||
|
return $this->platformLogisticsErrorReturn("缺少签名结果");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isset($request_params['nonce']) ){
|
||||||
|
Log::getInstance()->error("处方平台物流回调数据处理失败:缺少随机数");
|
||||||
|
return $this->platformLogisticsErrorReturn("缺少随机数");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isset($request_params['timestamp']) ){
|
||||||
|
Log::getInstance()->error("处方平台物流回调数据处理失败:缺少签名时间戳");
|
||||||
|
return $this->platformLogisticsErrorReturn("缺少签名时间戳");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isset($request_params['paramJsonStr']) ){
|
||||||
|
Log::getInstance()->error("处方平台物流回调数据处理失败:缺少数据体");
|
||||||
|
return $this->platformLogisticsErrorReturn("缺少数据体");
|
||||||
|
}
|
||||||
|
|
||||||
|
$param_json_str = json_decode($request_params['paramJsonStr'],true);
|
||||||
|
if (empty($param_json_str)){
|
||||||
|
Log::getInstance()->error("处方平台物流回调数据处理失败:数据体解析失败");
|
||||||
|
return $this->platformLogisticsErrorReturn("数据体解析失败");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
// 验证失败
|
||||||
|
Log::getInstance()->error("Im回调数据处理失败:" . $e->getMessage());
|
||||||
|
return $this->platformLogisticsErrorReturn($e->getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->platformLogisticsSuccessReturn();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 处方平台物流返回错误响应
|
||||||
|
* @param string $message
|
||||||
|
* @return ResponseInterface
|
||||||
|
*/
|
||||||
|
protected function platformLogisticsErrorReturn(string $message): ResponseInterface
|
||||||
|
{
|
||||||
|
return $this->response
|
||||||
|
->withStatus(200)
|
||||||
|
->withBody(
|
||||||
|
new SwooleStream(
|
||||||
|
strval(
|
||||||
|
json_encode([
|
||||||
|
'resultCode' => '0',
|
||||||
|
'resultDesc' => $message,
|
||||||
|
], JSON_UNESCAPED_UNICODE)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 处方平台物流返回正确响应
|
||||||
|
* @return ResponseInterface
|
||||||
|
*/
|
||||||
|
protected function platformLogisticsSuccessReturn(): ResponseInterface
|
||||||
|
{
|
||||||
|
return $this->response
|
||||||
|
->withStatus(200)
|
||||||
|
->withBody(
|
||||||
|
new SwooleStream(
|
||||||
|
strval(
|
||||||
|
json_encode([
|
||||||
|
'resultCode' => "1000",
|
||||||
|
'resultDesc' => "成功",
|
||||||
|
], JSON_UNESCAPED_UNICODE)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -20,7 +20,7 @@ class TestController extends AbstractController
|
|||||||
// $this->test_3();
|
// $this->test_3();
|
||||||
// $this->test_4();
|
// $this->test_4();
|
||||||
// $this->test_6();
|
// $this->test_6();
|
||||||
$this->test_9();
|
// $this->test_9();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -391,6 +391,12 @@ class TestController extends AbstractController
|
|||||||
public function test_9(){
|
public function test_9(){
|
||||||
$ca = new Ca();
|
$ca = new Ca();
|
||||||
$result = $ca->getSignedFile("491925054435950592","1638477783898161153");
|
$result = $ca->getSignedFile("491925054435950592","1638477783898161153");
|
||||||
|
if (empty($result)){
|
||||||
|
return fail();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 上传阿里云oss
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -265,18 +265,59 @@ class Ca
|
|||||||
*/
|
*/
|
||||||
public function getSignedFile(string $user_id, string $file_id): mixed
|
public function getSignedFile(string $user_id, string $file_id): mixed
|
||||||
{
|
{
|
||||||
$option = [
|
$arg = [
|
||||||
'form_params' => [
|
'form_params' => [
|
||||||
'userId' => $user_id,// 用户标识信息(为云证书entityId)
|
'userId' => $user_id,// 用户标识信息(为云证书entityId)
|
||||||
'fileId' => $file_id,// 签章接口返回的文件标识
|
'fileId' => $file_id,// 签章接口返回的文件标识
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
|
|
||||||
|
try {
|
||||||
|
$option = [
|
||||||
|
"headers" => [
|
||||||
|
"app_id" => config("ca.app_id"),
|
||||||
|
"signature" => $this->getRequestSign($arg),
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
$option = array_merge($arg, $option);
|
||||||
|
|
||||||
|
$response = $this->client->post(config("ca.api_url") . '/signature-server/api/open/signature/fetchSignedFile', $option);
|
||||||
|
|
||||||
|
if ($response->getStatusCode() != '200') {
|
||||||
|
// 请求失败
|
||||||
|
throw new BusinessException($response->getBody()->getContents());
|
||||||
|
}
|
||||||
|
|
||||||
|
// 将 Stream 对象转换为字符串
|
||||||
|
return (string)$response->getBody()->getContents();
|
||||||
|
} catch (GuzzleException $e) {
|
||||||
|
throw new BusinessException($e->getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PDF签章文件验证
|
||||||
|
* @param array $data
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function verifyPdf(array $data): mixed
|
||||||
|
{
|
||||||
|
$option = [
|
||||||
|
'multipart' => [
|
||||||
|
[
|
||||||
|
'name' => 'pdfFile',
|
||||||
|
'contents' => $data['pdf_file'],// 待签章PDF文件(字节流)
|
||||||
|
],
|
||||||
|
]
|
||||||
|
];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$response = $this->httpRequest(
|
$response = $this->httpRequest(
|
||||||
config("ca.api_url") . '/signature-server/api/open/signature/fetchSignedFile',
|
config("ca.api_url") . '/signature-server/api/open/signature/verifyPdf',
|
||||||
$option
|
$option
|
||||||
);
|
);
|
||||||
|
|
||||||
if (empty($response)) {
|
if (empty($response)) {
|
||||||
// 返回值为空
|
// 返回值为空
|
||||||
throw new BusinessException(HttpEnumCode::getMessage(HttpEnumCode::SERVER_ERROR));
|
throw new BusinessException(HttpEnumCode::getMessage(HttpEnumCode::SERVER_ERROR));
|
||||||
@ -287,7 +328,6 @@ class Ca
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取请求签名
|
* 获取请求签名
|
||||||
* @param array $data
|
* @param array $data
|
||||||
@ -311,11 +351,14 @@ class Ca
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ksort($sign_data);
|
if (!empty($sign_data)){
|
||||||
$data = implode('&', $sign_data);
|
ksort($sign_data);
|
||||||
|
$data = implode('&', $sign_data);
|
||||||
|
}else{
|
||||||
|
$data = "";
|
||||||
|
}
|
||||||
|
|
||||||
$data = hash_hmac("sha1", $data, config("ca.secret"));
|
return hash_hmac("sha1", $data, config("ca.secret"));
|
||||||
return $data;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user