feat: 修改异常处理器和API接口,增加错误信息和日志记录功能

This commit is contained in:
mkm 2024-06-05 12:36:59 +08:00
parent 6e20a3a833
commit e373631ff3
3 changed files with 66 additions and 26 deletions

View File

@ -37,6 +37,6 @@ class ExceptionHandler extends Handler
return response(json_encode($error, JSON_UNESCAPED_UNICODE)); return response(json_encode($error, JSON_UNESCAPED_UNICODE));
} }
// 非json请求则返回一个页面 // 非json请求则返回一个页面
return new Response(200, [], $exception->getMessage()); return new Response(200, [], 'msg:'.$exception->getMessage().'。line:'.$exception->getLine().'。file:'.$exception->getFile());
} }
} }

View File

@ -5,9 +5,14 @@ namespace app\api\controller;
use app\admin\validate\tools\GenerateTableValidate; use app\admin\validate\tools\GenerateTableValidate;
use app\admin\logic\tools\GeneratorLogic; use app\admin\logic\tools\GeneratorLogic;
use app\common\logic\store_order\StoreOrderLogic; use app\common\logic\store_order\StoreOrderLogic;
use app\common\service\pay\PayService;
use app\common\service\wechat\WechatTemplate;
use Exception;
use think\facade\Db; use think\facade\Db;
use Webman\Config; use Webman\Config;
use hg\apidoc\annotation as ApiDoc; use hg\apidoc\annotation as ApiDoc;
use Yansongda\Pay\Exception\InvalidSignException;
#[ApiDoc\NotParse()] #[ApiDoc\NotParse()]
class IndexController extends BaseApiController class IndexController extends BaseApiController
@ -16,9 +21,40 @@ class IndexController extends BaseApiController
public function index() public function index()
{ {
try{
$a=new WechatTemplate();
$a->NewQuotationNotification(['openid'=>'ocqhF6UfFQXE-SbzbP5YVQJlQAh0','data1'=>'阿萨','data2'=>date('Y-m-d H:i:s'),'data3'=>'占山','data3'=>18982406440]);
}catch (Exception $e){
d($e);
}
d(2);
d(22);
$auth_code = $this->request->get('code');
$pay = (new PayService());
$order = [
'description' => '条码商品',
'out_trade_no' => (string)time(),
'payer' => [
'auth_code' => (string)$auth_code
],
'amount' => [
'total' =>1,
],
'scene_info' => [
"store_info" => [
'id' => '1'
]
],
];
try{
$a= $pay->wechat->pos($order);
}catch (\Exception $th) {
d($th);
}
d($a);
$params = ['store_id' => 2, 'pay_type' => 17]; $params = ['store_id' => 2, 'pay_type' => 17];
$a = StoreOrderLogic::createOrder([1], 0, null, $params); $a = StoreOrderLogic::createOrder([1], 0, null, $params);
d($a); d($a);
@ -41,7 +77,8 @@ class IndexController extends BaseApiController
/** /**
* @notes 获取app更新信息 * @notes 获取app更新信息
*/ */
public function app_update(){ public function app_update()
{
$find = Db::name('app_update')->where('type', 2)->order('id', 'desc')->findOrEmpty(); $find = Db::name('app_update')->where('type', 2)->order('id', 'desc')->findOrEmpty();
return $this->success('ok', $find); return $this->success('ok', $find);
} }
@ -50,14 +87,16 @@ class IndexController extends BaseApiController
/** /**
* @notes 获取省列表 * @notes 获取省列表
*/ */
public function province(){ public function province()
{
$list = Db::name('geo_province')->select()->toArray(); $list = Db::name('geo_province')->select()->toArray();
return $this->success('ok', $list); return $this->success('ok', $list);
} }
/** /**
* @notes 获取市列表 * @notes 获取市列表
*/ */
public function city(){ public function city()
{
$province_code = $this->request->get('code'); $province_code = $this->request->get('code');
$list = Db::name('geo_city')->where('province_code', $province_code)->select()?->toArray(); $list = Db::name('geo_city')->where('province_code', $province_code)->select()?->toArray();
return $this->success('ok', $list); return $this->success('ok', $list);
@ -65,7 +104,8 @@ class IndexController extends BaseApiController
/** /**
* @notes 获取区列表 * @notes 获取区列表
*/ */
public function area(){ public function area()
{
$city_code = $this->request->get('code'); $city_code = $this->request->get('code');
$list = Db::name('geo_area')->where('city_code', $city_code)->select()?->toArray(); $list = Db::name('geo_area')->where('city_code', $city_code)->select()?->toArray();
return $this->success('ok', $list); return $this->success('ok', $list);
@ -73,10 +113,10 @@ class IndexController extends BaseApiController
/** /**
* @notes 获取街道列表 * @notes 获取街道列表
*/ */
public function street(){ public function street()
{
$area_code = $this->request->get('area_code'); $area_code = $this->request->get('area_code');
$list = Db::name('geo_street')->where('area_code', $area_code)->select()?->toArray(); $list = Db::name('geo_street')->where('area_code', $area_code)->select()?->toArray();
return $this->success('ok', $list); return $this->success('ok', $list);
} }
} }

View File

@ -49,7 +49,7 @@ class WechatTemplate
'data' => [ 'data' => [
'thing2' => ['value' => $data['data1']], 'thing2' => ['value' => $data['data1']],
'thing3' => ['value' => $data['data2']], 'thing3' => ['value' => $data['data2']],
'const4' => ['value' => $data['data3']??08302669767], 'const4' => ['value' => $data['data3']??'08302669767'],
] ]
]; ];
return $this->post($template); return $this->post($template);