开发ca,修正手机号获取验证码log表

This commit is contained in:
wucongxing 2023-03-21 20:35:27 +08:00
parent 45e8b8ae6b
commit 563e5ca7ba
8 changed files with 261 additions and 20 deletions

View File

@ -17,6 +17,14 @@ class SendSmsMessageConsumer extends ConsumerMessage
{
public function consumeMessage($data, AMQPMessage $message): string
{
/**
* data = [
* "code" => "SMS_123",
* "data" => [
* // data内参数不确定主要看短信模版
* ],
* ]
*/
return Result::ACK;
}
}

View File

@ -2,17 +2,20 @@
namespace App\Controller;
use App\Amqp\Producer\CancelUnpayOrdersDelayDirectProducer;
use App\Constants\HttpEnumCode;
use App\Model\DoctorPharmacistCert;
use Extend\Alibaba\Oss;
use Extend\Ca\Ca;
use Hyperf\Amqp\Producer;
use Hyperf\DbConnection\Db;
use Intervention\Image\ImageManager;
use TCPDF;
class TestController extends AbstractController
{
public function test(){
$this->test_5();
$this->test_7();
}
// 获取云证书-首次
@ -49,7 +52,7 @@ class TestController extends AbstractController
// 获取云证书签名
$data = array();
$data['created_at'] = date('Y-m-d H:i:s',time());
$data['created_at'] = "2023-03-01 12:44:10";
$data['department_custom_name'] = "外科";
$data['user_name'] = "测试用户1";
$data['sex'] = "";
@ -71,7 +74,28 @@ class TestController extends AbstractController
"frequency_use" => "1天3次",
"single_use" => "口服",
"prescription_product_num" => "X1盒",
]
],
[
"product_name" => "感冒药350ml*10",
"single_unit" => "一次一包",
"frequency_use" => "1天3次",
"single_use" => "口服",
"prescription_product_num" => "X1盒",
],
[
"product_name" => "感冒药450ml*10",
"single_unit" => "一次一包",
"frequency_use" => "1天3次",
"single_use" => "口服",
"prescription_product_num" => "X1盒",
],
[
"product_name" => "感冒药550ml*10",
"single_unit" => "一次一包",
"frequency_use" => "1天3次",
"single_use" => "口服",
"prescription_product_num" => "X1盒",
],
];
$result = $ca->getCertSign("491925054435950592","491925054435950592",$data);
@ -271,8 +295,94 @@ class TestController extends AbstractController
}
// 将处理后的图片重新保存到其他路径
$image->save('./runtime/2.jpg');
// $image->save('./runtime/2.jpg');
$result = (string) $image->encode('png', 75);
// 图片生成pdf
$pdf = new TCPDF('P', 'mm', 'A4', true, 'UTF-8', false);
$pdf->AddPage();
$pdf->Image('@' . $result, 10, 10, 0, 0, '', '', '', false, 300, '', false, false, 0, false, false, false);
return $pdf->Output("","S");
}
// pdf进行签章
public function test_6(){
$pdf_file = $this->test_5();
$pdf_file = base64_encode($pdf_file);
if (!$pdf_file){
return fail(HttpEnumCode::SERVER_ERROR);
}
$pdf_file = urlencode($pdf_file);
$oss = new Oss();
$filename = "applet/doctor/cert/67d7396d-0fc3-464d-9582-3501229ed188.png";
$style = "image/resize,m_lfit,w_350,h_100/rotate";
$sign_image = $oss->getCusTomObjectToRAM($filename,$style);
$sign_image = base64_encode($sign_image);
if (!$sign_image){
return fail(HttpEnumCode::SERVER_ERROR);
}
$sign_image = urlencode($sign_image);
$sign_param = [
[
"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['pdf_file'] = $pdf_file;
$ca = new Ca();
$result = $ca->addSignPdf("491925054435950592",$data);
dump($result);
}
// 延迟队列测试
public function test_7(){
$out_trade_no = $this->request->input('out_trade_no');
if ($out_trade_no == 1){
// 增加至取消订单延迟队列
$data = array();
$data['order_no'] = 111;
$data['order_type'] = 1;
$message = new CancelUnpayOrdersDelayDirectProducer($data);
$message->setDelayMs(1000 * 5 * 1);
$producer = $this->container->get(Producer::class);
$res = $producer->produce($message);
if (!$res) {
Db::rollBack();
return fail(HttpEnumCode::SERVER_ERROR, "订单创建失败");
}
}else{
// 增加至取消订单延迟队列
$data = array();
$data['order_no'] = 2222;
$data['order_type'] = 1;
$message = new CancelUnpayOrdersDelayDirectProducer($data);
$message->setDelayMs(1000 * 15 * 1);
$producer = $this->container->get(Producer::class);
$res = $producer->produce($message);
if (!$res) {
Db::rollBack();
return fail(HttpEnumCode::SERVER_ERROR, "订单创建失败");
}
}
}
}

View File

@ -21,14 +21,14 @@ use Hyperf\Snowflake\Concern\Snowflake;
* @property \Carbon\Carbon $created_at 创建时间
* @property \Carbon\Carbon $updated_at 修改时间
*/
class LogPushMessage extends Model
class LogMessagePush extends Model
{
use Snowflake;
/**
* The table associated with the model.
*/
protected ?string $table = 'log_push_message';
protected ?string $table = 'log_message_push';
/**
* The attributes that are mass assignable.

View File

@ -20,19 +20,19 @@ use Hyperf\Snowflake\Concern\Snowflake;
* @property \Carbon\Carbon $created_at 创建时间
* @property \Carbon\Carbon $updated_at 修改时间
*/
class LogCode extends Model
class LogSms extends Model
{
use Snowflake;
/**
* The table associated with the model.
*/
protected ?string $table = 'log_code';
protected ?string $table = 'log_sms';
/**
* The attributes that are mass assignable.
*/
protected array $fillable = ['log_id', 'type', 'status', 'scene', 'phone', 'code', 'third_code', 'remarks', 'created_at', 'updated_at'];
protected array $fillable = ['log_id', 'type', 'status', 'phone', 'template_code', 'third_code', 'scene_desc', 'remarks', 'created_at', 'updated_at'];
protected string $primaryKey = "log_id";
@ -63,9 +63,9 @@ class LogCode extends Model
/**
* 新增-批量
* @param array $data
* @return \Hyperf\Database\Model\Model|LogCode
* @return \Hyperf\Database\Model\Model|LogSms
*/
public static function addCodeLog(array $data): \Hyperf\Database\Model\Model|LogCode
public static function addCodeLog(array $data): \Hyperf\Database\Model\Model|LogSms
{
return self::create($data);
}

View File

@ -0,0 +1,86 @@
<?php
declare(strict_types=1);
namespace App\Model;
use Hyperf\Database\Model\Collection;
use Hyperf\Snowflake\Concern\Snowflake;
/**
* @property int $notice_id 主键id
* @property int $user_id 用户id接受者
* @property int $user_type 用户类型1:患者端 2:医师端 3:药师端)
* @property int $notice_type 消息类型1:医生服务通知 2:医生系统公告 3:患者系统消息)
* @property int $notice_system_type 系统消息类型(患者端系统消息存在 1:服务消息 2:福利消息 3:退款消息 4:物流消息)
* @property string $from_name 发送人姓名
* @property string $notice_title 消息标题
* @property string $notice_send_time 发送时间
* @property string $notice_content 内容
* @property int $send_status 发送状态0:未处理 1:已发送 2:发送失败)
* @property string $send_fail_reason 发送失败原因
* @property int $link_type 链接类型1:无按钮 2:我的账户 3:联系客服 4:问诊消息 5:多点执业认证 6:协议书)
* @property string $notice_params 通知参数json数据此字段内容和link_type字段有关联
* @property \Carbon\Carbon $created_at 创建时间
* @property \Carbon\Carbon $updated_at 修改时间
*/
class MessageNotice extends Model
{
use Snowflake;
/**
* The table associated with the model.
*/
protected ?string $table = 'message_notice';
/**
* The attributes that are mass assignable.
*/
protected array $fillable = ['notice_id', 'user_id', 'user_type', 'notice_type', 'notice_system_type', 'from_name', 'notice_title', 'notice_send_time', 'notice_content', 'send_status', 'send_fail_reason', 'link_type', 'notice_params', 'created_at', 'updated_at'];
protected string $primaryKey = "message_id";
/**
* 获取是否存在
* @param array $params
* @return bool
*/
public static function getExists(array $params): bool
{
return self::where($params)->exists();
}
/**
* 获取信息-单条
* @param array $params
* @param array $fields
* @return object|null
*/
public static function getOne(array $params, array $fields = ['*']): object|null
{
return self::where($params)->first($fields);
}
/**
* 获取数据-
* @param array $params
* @param array $fields
* @return Collection|array
*/
public static function getList(array $params = [], array $fields = ['*']): Collection|array
{
return self::where($params)->get($fields);
}
/**
* 新增
* @param array $data
* @return MessageNotice|\Hyperf\Database\Model\Model
*/
public static function addMessageNotice(array $data): MessageNotice|\Hyperf\Database\Model\Model
{
return self::create($data);
}
}

View File

@ -44,7 +44,7 @@ class CodeService extends BaseService
$template_param['code'] = mt_rand(1,9) . (int)substr($generator->generate(),-3);
// 发送短信
Dysms::sendSms($phone,$template_param,$template_code,1);
Dysms::sendSms($phone,$template_param,$template_code,"获取验证码");
if (empty($result)){
$redis_value = 1;

View File

@ -3,7 +3,7 @@ namespace Extend\Alibaba;
use App\Constants\HttpEnumCode;
use App\Exception\BusinessException;
use App\Model\LogCode;
use App\Model\LogSms;
use Darabonba\OpenApi\OpenApiClient;
use AlibabaCloud\OpenApiUtil\OpenApiUtilClient;
@ -68,9 +68,9 @@ class Dysms
* @param string $phone_numbers 手机号
* @param array $template_param 参数
* @param string $template_code 短信模版编码
* @param int $scene 场景
* @param int $scene_desc 场景
*/
public static function sendSms(string $phone_numbers,array $template_param,string $template_code,int $scene): void
public static function sendSms(string $phone_numbers,array $template_param,string $template_code,int $scene_desc): void
{
$config = config("alibaba.dysms");
@ -113,12 +113,12 @@ class Dysms
$data = array();
$data['type'] = 1;
$data['status'] = 1;
$data['scene'] = $scene;
$data['phone'] = $phone_numbers;
$data['code'] = $template_code;
$data['template_code'] = $template_code;
$data['third_code'] = $result['body']['RequestId'];
$data['scene_desc'] = $scene_desc;
$data['remarks'] = json_encode($template_param,JSON_UNESCAPED_UNICODE);
$res = LogCode::addCodeLog($data);
$res = LogSms::addCodeLog($data);
if (empty($res)){
// 发送成功,记录失败
throw new BusinessException(HttpEnumCode::getMessage(HttpEnumCode::CODE_FAIL));

View File

@ -4,6 +4,7 @@ namespace Extend\Ca;
use App\Constants\HttpEnumCode;
use App\Exception\BusinessException;
use App\Utils\Log;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\GuzzleException;
use Hyperf\Di\Annotation\Inject;
@ -182,6 +183,36 @@ class Ca
}
}
/**
* PDF添加电子签章
*/
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码云证书签章时使用
]
];
try {
$response = $this->httpRequest(
config("ca.api_url") . '/signature-server/api/open/signature/signPdf',
$option
);
if (empty($response)){
// 返回值为空
throw new BusinessException(HttpEnumCode::getMessage(HttpEnumCode::SERVER_ERROR));
}
return $response;
} catch (GuzzleException $e) {
throw new BusinessException($e->getMessage());
}
}
/**
* 获取请求签名
* @param array $data
@ -190,6 +221,12 @@ 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]);
}
}
$data = implode('&',$data['form_params']);
return hash_hmac("sha1",$data,config("ca.secret"));
@ -204,7 +241,6 @@ class Ca
*/
protected function httpRequest(string $path,array $arg = []): mixed
{
$option = [
"headers" => [
"app_id" => config("ca.app_id"),
@ -214,9 +250,10 @@ class Ca
$arg = array_merge($arg,$option);
// dump(json_encode($arg,JSON_UNESCAPED_UNICODE));
// dump(json_encode($arg,JSON_UNESCAPED_UNICODE));
$response = $this->client->post($path, $arg);
if ($response->getStatusCode() != '200'){
// 请求失败
throw new BusinessException($response->getBody()->getContents());