修正验证吗

This commit is contained in:
wucongxing 2023-03-22 15:15:33 +08:00
parent 563e5ca7ba
commit 26fc5f5e62
12 changed files with 326 additions and 59 deletions

View File

@ -4,10 +4,18 @@ declare(strict_types=1);
namespace App\Amqp\Consumer;
use App\Constants\HttpEnumCode;
use App\Exception\BusinessException;
use App\Model\LogSms;
use App\Utils\Log;
use Extend\Alibaba\Dysms;
use Hyperf\Amqp\Result;
use Hyperf\Amqp\Annotation\Consumer;
use Hyperf\Amqp\Message\ConsumerMessage;
use Hyperf\Redis\Redis;
use PhpAmqpLib\Message\AMQPMessage;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
/**
* 发送短信
@ -19,12 +27,172 @@ class SendSmsMessageConsumer extends ConsumerMessage
{
/**
* data = [
* "code" => "SMS_123",
* "data" => [
* // data内参数不确定,主要看短信模版
* "template_code" => "SMS_123",
* "template_param" => [
* // 参数不确定,主要看短信模版的不同
* ],
* "scene_desc" => "场景描述",
* "phone" => "手机号",
* "user_id" => "用户id被推送者"
* ]
*/
Log::getInstance()->error("开始执行 发送短信 队列:" . json_encode($data, JSON_UNESCAPED_UNICODE));
if (!isset($data['template_code']) || !isset($data['template_param'])){
Log::getInstance()->error("发送短信失败:发送参数错误");
return Result::DROP;// 销毁
}
// 验证发送参数
$res = $this->checkTemplateParam($data['template_code'],$data['template_param']);
if (!$res){
Log::getInstance()->error("发送短信失败:发送参数错误");
return Result::DROP;// 销毁
}
try {
$redis = $this->container->get(Redis::class);
$redis_key = "sms_" . $data['phone'] . $data['template_code'];
$result = $redis->get($redis_key);
if (!empty($result)){
if ( $result > 3){
// 超出规定时间内最大获取次数
Log::getInstance()->error("发送短信失败:超出最大发送重试次数");
return Result::DROP;// 销毁
}
}
// 发送短信
Dysms::sendSms($data['phone'],$data['template_param'],$data['template_code'],$data['scene_desc']);
} catch (\Exception $e) {
Log::getInstance()->error("发送短信失败:" . $e->getMessage());
return Result::REQUEUE; // 重回队列
} catch (NotFoundExceptionInterface|ContainerExceptionInterface $e) {
Log::getInstance()->error("发送短信失败:" . $e->getMessage());
return Result::DROP; // 销毁
}
return Result::ACK;
}
/**
* 验证短信发送参数
* @param string $template_code
* @param array $template_param
* @return bool
*/
private function checkTemplateParam(string $template_code, array $template_param): bool
{
switch ($template_code) {
case 'SMS_271990126':
// 医生修改简介审核通过
break;
case 'SMS_271540920':
// 处方审核通过通知患者
if (!isset($template_param['name'])) {
return false;
}
case 'SMS_271905266':
// 医师还未接诊
if (!isset($template_param['name']) || !isset($template_param['type'])) {
return false;
}
break;
case 'SMS_272140100':
// 药品收货-用药提醒
if (!isset($template_param['name']) || !isset($template_param['usage']) || !isset($template_param['frequency']) || !isset($template_param['amount']) || !isset($template_param['tell'])) {
return false;
}
break;
case 'SMS_271575911':
// 多点执业认证通过
break;
case 'SMS_271955088':
// 医生接诊通知给患者
if (!isset($template_param['type']) || !isset($template_param['name']) || !isset($template_param['duration'])) {
return false;
}
break;
case 'SMS_271905264':
// 处方审核拒绝通过医师
if (!isset($template_param['name'])) {
return false;
}
break;
case 'SMS_271980127':
// 药品已发货
if (!isset($template_param['name']) || !isset($template_param['code'])) {
return false;
}
break;
case 'SMS_272180110':
// 患者问诊费退款
if (!isset($template_param['type'])) {
return false;
}
break;
case 'SMS_272145102':
// 医生没有及时回消息
if (!isset($template_param['name']) || !isset($template_param['type'])) {
return false;
}
break;
case 'SMS_272120097':
// 处方审核通过通知医生
if (!isset($template_param['name'])) {
return false;
}
break;
case 'SMS_272030021':
// 多点执业认证拒绝
break;
case 'SMS_271925089':
// 医师身份认证通过
break;
case 'SMS_271915200':
// 医师服务费结算
if (!isset($template_param['name']) || !isset($template_param['time'])) {
return false;
}
break;
case 'SMS_272015117':
// 医生接到新问诊
if (!isset($template_param['type'])) {
return false;
}
break;
case 'SMS_271955204':
// 患者药品费用退款
if (!isset($template_param['name']) || !isset($template_param['status'])) {
return false;
}
break;
case 'SMS_271905155':
// 医师身份认证拒绝
break;
case 'SMS_271950089':
// 问诊即将结束通知患者
if (!isset($template_param['name']) || !isset($template_param['type']) || !isset($template_param['time'])) {
return false;
}
break;
case 'SMS_272165092':
// 医生修改简介审核拒绝
break;
default:
// code...
break;
}
return true;
}
// 记录发送失败log
private function addSendFailLog(array $data){
$data = array();
// $data['to_user_id']
}
}

View File

@ -732,4 +732,9 @@ class CallBackController extends AbstractController
);
}
// 处方平台物流回调
public function platformLogisticsCallBack(){
}
}

View File

@ -5,6 +5,7 @@ namespace App\Controller;
use App\Amqp\Producer\CancelUnpayOrdersDelayDirectProducer;
use App\Constants\HttpEnumCode;
use App\Model\DoctorPharmacistCert;
use App\Utils\Log;
use Extend\Alibaba\Oss;
use Extend\Ca\Ca;
use Hyperf\Amqp\Producer;
@ -15,7 +16,12 @@ use TCPDF;
class TestController extends AbstractController
{
public function test(){
$this->test_7();
// $this->test_8();
// $this->test_3();
// $this->test_4();
$this->test_6();
}
// 获取云证书-首次
@ -111,9 +117,9 @@ class TestController extends AbstractController
// 下载阿里云图片
$oss = new Oss();
$filename = "applet/doctor/cert/67d7396d-0fc3-464d-9582-3501229ed188.png";
$filename = "applet/doctor/cert/b09ebb06-be90-40cf-9329-fab5b15139ec.png";
$style = "image/resize,m_lfit,w_100,h_350/rotate,270";
$style = "image/resize,m_lfit,w_100,h_350";
$sign_image = $oss->getCusTomObjectToRAM($filename,$style);
$sign_image = base64_encode($sign_image);
@ -121,20 +127,18 @@ class TestController extends AbstractController
return fail(HttpEnumCode::SERVER_ERROR);
}
$sign_image = urlencode($sign_image);
$sign_param = [
[
"llx"=> 700, // 左边底部X坐标
"lly"=>2985, // 左边底部Y坐标
"urx"=>1101, // 右边上部x坐标
"ury"=>2896, // 右边上部y坐标
"llx"=> "700", // 左边底部X坐标
"lly"=>"2985", // 左边底部Y坐标
"urx"=>"1101", // 右边上部x坐标
"ury"=>"2896", // 右边上部y坐标
"pageList"=>[1],
"sealImg"=>$sign_image
]
];
$data = array();
$data['sign_param'] = json_encode($sign_param,JSON_UNESCAPED_UNICODE);
$data['sign_param'] = json_encode($sign_param);
$data['seal_img'] = $sign_image;
$result = $ca->addUserSignConfig("491925054435950592","410323199603261241",$data);
@ -311,18 +315,21 @@ class TestController extends AbstractController
public function test_6(){
$pdf_file = $this->test_5();
$pdf_file = base64_encode($pdf_file);
if (!$pdf_file){
return fail(HttpEnumCode::SERVER_ERROR);
}
// $oss = new Oss();
// $filename = "Basic/images/prescription_img.jpg";
//
// $pdf_file = $oss->getObjectToRAM($filename);
// $pdf_file = file_get_contents('./runtime/dsddasdasdasdasdasdsa.pdf');
$pdf_file = urlencode($pdf_file);
// $pdf_file = new \CURLFILE('./runtime/dsddasdasdasdasdasdsa.pdf');
// $pdf_file = fopen("/Users/wucongxing/Desktop/work/php/hospital-applets-api/runtime/dsddasdasdasdasdasdsa.pdf",'f');
// dump($pdf_file);die;
$oss = new Oss();
$filename = "applet/doctor/cert/67d7396d-0fc3-464d-9582-3501229ed188.png";
$filename = "applet/doctor/cert/b09ebb06-be90-40cf-9329-fab5b15139ec.png";
$style = "image/resize,m_lfit,w_350,h_100/rotate";
$style = "image/resize,m_lfit,w_100,h_350";
$sign_image = $oss->getCusTomObjectToRAM($filename,$style);
$sign_image = base64_encode($sign_image);
@ -330,21 +337,20 @@ class TestController extends AbstractController
return fail(HttpEnumCode::SERVER_ERROR);
}
$sign_image = urlencode($sign_image);
// $sign_image = urlencode($sign_image);
$sign_param = [
[
"llx"=> 700, // 左边底部X坐标
"lly"=>2985, // 左边底部Y坐标
"urx"=>1101, // 右边上部x坐标
"ury"=>2896, // 右边上部y坐标
"llx"=> "700", // 左边底部X坐标
"lly"=>"2985", // 左边底部Y坐标
"urx"=>"1101", // 右边上部x坐标
"ury"=>"2896", // 右边上部y坐标
"pageList"=>[1],
"sealImg"=>$sign_image
]
];
$data = array();
$data['sign_param'] = json_encode($sign_param,JSON_UNESCAPED_UNICODE);
$data['sign_param'] = json_encode($sign_param);
$data['pdf_file'] = $pdf_file;
$ca = new Ca();
@ -385,4 +391,10 @@ class TestController extends AbstractController
}
}
}
// 删除签章配置
public function test_8(){
$ca = new Ca();
$result = $ca->deleteUserSignConfig("491925054435950592");
}
}

View File

@ -64,4 +64,6 @@ class UserPatientController extends AbstractController
return $this->response->json($data);
}
// public function
}

View File

@ -65,7 +65,7 @@ class LogSms extends Model
* @param array $data
* @return \Hyperf\Database\Model\Model|LogSms
*/
public static function addCodeLog(array $data): \Hyperf\Database\Model\Model|LogSms
public static function LogSms(array $data): \Hyperf\Database\Model\Model|LogSms
{
return self::create($data);
}

View File

@ -36,7 +36,7 @@ class PatientCaseService extends BaseService
$order_inquiry_case = OrderInquiryCase::getEndOrderInquiryCaseOne($params,$order_inquiry_params);
if (empty($order_inquiry_case)){
return success();
return success('');
}
$order_inquiry_case = $order_inquiry_case->toArray();

View File

@ -28,6 +28,7 @@ class Auth
"/callback/wxpay/product/success" => "post", // 微信药品支付回调
"/callback/wxpay/product/refund" => "post", // 微信药品退款回调
"/callback/im" => "post", // im回调
"/callback/platform/logistics" => "post", // 处方平台物流回调
"/test" => "get", // 测试
];
}

View File

@ -39,7 +39,8 @@
"intervention/image": "^2.7",
"tecnickcom/tcpdf": "^6.6",
"w7corp/easywechat": "^6.7",
"ext-gd": "*"
"ext-gd": "*",
"ext-curl": "*"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.0",

View File

@ -297,6 +297,20 @@ Router::addGroup('/patient', function () {
Router::get('/last/{family_id:\d+}', [PatientCaseController::class, 'getLastCase']);
});
// 药品
Router::addGroup('/product', function () {
Router::addGroup('/shopping', function () {
// 获取购物车
Router::get('/cart', [UserPatientController::class, 'addShoppingCart']);
// 添加购物车
Router::post('/cart', [UserPatientController::class, 'addShoppingCart']);
// 修改购物车
Router::put('/cart', [UserPatientController::class, 'putShoppingCart']);
});
});
// 订单
Router::addGroup('/order', function () {
Router::addGroup('/inquiry', function () {
@ -503,6 +517,9 @@ Router::addGroup('/callback', function () {
// im回调
Router::post('/im', [CallBackController::class, 'imCallBack']);
// 处方平台物流回调
Router::post('/platform/logistics', [CallBackController::class, 'platformLogisticsCallBack']);
});
// 用户

View File

@ -68,9 +68,9 @@ class Dysms
* @param string $phone_numbers 手机号
* @param array $template_param 参数
* @param string $template_code 短信模版编码
* @param int $scene_desc 场景
* @param string $scene_desc 场景
*/
public static function sendSms(string $phone_numbers,array $template_param,string $template_code,int $scene_desc): void
public static function sendSms(string $phone_numbers,array $template_param,string $template_code,string $scene_desc = ""): void
{
$config = config("alibaba.dysms");
@ -116,9 +116,9 @@ class Dysms
$data['phone'] = $phone_numbers;
$data['template_code'] = $template_code;
$data['third_code'] = $result['body']['RequestId'];
$data['scene_desc'] = $scene_desc;
$data['scene_desc'] = $scene_desc ?: "";
$data['remarks'] = json_encode($template_param,JSON_UNESCAPED_UNICODE);
$res = LogSms::addCodeLog($data);
$res = LogSms::LogSms($data);
if (empty($res)){
// 发送成功,记录失败
throw new BusinessException(HttpEnumCode::getMessage(HttpEnumCode::CODE_FAIL));

View File

@ -110,9 +110,14 @@ class Oss
public function getCusTomObjectToRAM(string $filename,string $style = "image/resize"): string
{
try {
// $download_file = "./runtime/aaa.jpg";
$ossClient = $this->createClient();
$options = array(
OssClient::OSS_PROCESS => $style);
OssClient::OSS_PROCESS => $style,
// OssClient::OSS_FILE_DOWNLOAD => $download_file,
);
$object = $filename;
return $ossClient->getObject($this->config['bucket'], $object,$options);

View File

@ -5,6 +5,7 @@ namespace Extend\Ca;
use App\Constants\HttpEnumCode;
use App\Exception\BusinessException;
use App\Utils\Log;
use Exception;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\GuzzleException;
use Hyperf\Di\Annotation\Inject;
@ -136,7 +137,7 @@ class Ca
'signParam' => $data['sign_param'], // 签章配置,JSON
'sealImg' => $data['seal_img'], // 签章图片base64格式
'sealType' => "4",
'signTemplate' => "1",
'signTemplate' => "0",
]
];
@ -145,11 +146,33 @@ class Ca
config("ca.api_url") . '/signature-server/api/open/signature/userSignConfig',
$option
);
if (empty($response)){
// 返回值为空
throw new BusinessException(HttpEnumCode::getMessage(HttpEnumCode::SERVER_ERROR));
}
return $response;
return true;
} catch (GuzzleException $e) {
throw new BusinessException($e->getMessage());
}
}
/**
* 删除签章配置
* @param string $user_id
* @return mixed
*/
public function deleteUserSignConfig(string $user_id): mixed
{
$option = [
'form_params' => [
'userId' => $user_id,//用户标识信息为云证书entityId
'configKey' => $user_id, // 签章配置唯一标识,一张云证书配置一个
]
];
try {
$this->httpRequest(
config("ca.api_url") . '/signature-server/api/open/signature/delSignConfig',
$option
);
return true;
} catch (GuzzleException $e) {
throw new BusinessException($e->getMessage());
}
@ -188,12 +211,34 @@ class Ca
*/
public function addSignPdf(string $user_id,array $data){
$option = [
'form_params' => [
'userId' => $user_id,// 用户标识信息
'configKey' => $user_id,// 签章配置唯一标识
'signParams' => $data['sign_param'],// 签章参数JSON格式数据,如果不指定,那么以签章配置接口配置为准
'pdfFile' => $data['pdf_file'],// 待签章PDF文件字节流
'cloudCertPass' => $user_id,// 云证书PIN码云证书签章时使用
// 'form_params' => [
// 'userId' => $user_id,// 用户标识信息
// 'configKey' => $user_id,// 签章配置唯一标识
// 'signParams' => $data['sign_param'],// 签章参数JSON格式数据,如果不指定,那么以签章配置接口配置为准
// 'pdfFile' => $data['pdf_file'],// 待签章PDF文件字节流
// 'cloudCertPass' => $user_id,// 云证书PIN码云证书签章时使用
// ],
'multipart' => [
[
'name' => 'pdfFile',
'contents' => $data['pdf_file'],
],
[
'name' => 'userId',
'contents' => $user_id, // 用户标识信息
],
[
'name' => 'configKey',
'contents' => $user_id, // 签章配置唯一标识
],
[
'name' => 'signParams',
'contents' => $data['sign_param'],// 签章参数JSON格式数据,如果不指定,那么以签章配置接口配置为准
],
[
'name' => 'cloudCertPass',
'contents' => $user_id,// 云证书PIN码云证书签章时使用
],
]
];
@ -213,6 +258,8 @@ class Ca
}
}
/**
* 获取请求签名
* @param array $data
@ -220,16 +267,23 @@ class Ca
*/
protected function getRequestSign(array $data): string
{
ksort($data['form_params']);
foreach ($data['form_params'] as $key => $item){
if ($key == "pdfFile"){
// pdf进行签章时此参数为文件流不参与签名
unset($data['form_params'][$key]);
}
}
// pdf进行签章时此参数为文件流不参与签名
unset($data['form_params']['pdfFile']);
// signParams参数计算时不进行urlencode处理
// if (isset($data['form_params']['signParams'])){
// $sign_param = json_decode($data['form_params']['signParams'],true);
// $sign_param[0]['sealImg'] = urldecode($sign_param[0]['sealImg']);
//
// $data['form_params']['signParams'] = json_encode($sign_param);
// }
ksort($data['form_params']);
$data = implode('&',$data['form_params']);
return hash_hmac("sha1",$data,config("ca.secret"));
dump($data);
$data = hash_hmac("sha1",$data,config("ca.secret"));
return $data;
}
/**
@ -244,15 +298,17 @@ class Ca
$option = [
"headers" => [
"app_id" => config("ca.app_id"),
"signature" => $this->getRequestSign($arg)
"signature" => $this->getRequestSign($arg),
],
];
$arg = array_merge($arg,$option);
// dump(json_encode($arg,JSON_UNESCAPED_UNICODE));
$response = $this->client->post($path, $arg);
try {
$response = $this->client->post($path, $arg);
}catch(\Exception $e){
dump($e->getMessage());
}
if ($response->getStatusCode() != '200'){
// 请求失败