123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433 |
- <?php
- /**
- * Created by PhpStorm.
- * User: shensong
- * Date: 2022/3/16
- * Time: 13:43
- */
- namespace App\Http\Controllers\Admin;
- use App\Console\Commands\JiaShuOrderToRds;
- use App\Console\Commands\MaiBuOrderToRds;
- use App\Http\Controllers\Controller;
- use App\Log;
- use App\Models\PlatformOrderConf;
- use App\RedisModel;
- use App\Service\CapacityService;
- use App\Service\DjOrderService;
- use App\Service\HttpService;
- use App\Service\MsgService;
- use App\Support\EmailQueue;
- use Illuminate\Http\Request;
- class CallBackController extends Controller
- {
- private $token = 'oPIOwRVCWLDi5wXR'; // 柚子分销token
- private $jiashuToken = 'OHDj8EJfoYrWF5rX';// 嘉书分销token
- /*
- * 杭州猎豆 柚子分销平台
- */
- public function youziOrderCallBack(Request $request)
- {
- $msgType = $request->input('msgType');
- $timestamp = $request->input('timestamp');
- $nonce = $request->input('nonce');
- $signature = $request->input('signature');
- $orderPay = $request->input('orderPay');
- $platformId = $request->input('platformId');
- $sysPlatformId = 'BcJV6mb504Kt2lML';
- if(empty($orderPay)) {
- // 在柚子端填写回调地址回调使用
- return 'success';
- }
- // 将接收到的数据保存的日志文件中
- Log::logInfo(json_encode($request->all(), JSON_UNESCAPED_UNICODE), [$platformId], 'youziOrder');
- # 此处逻辑为在柚子后台配置回传链接时使用
- if($msgType != 'orderPay') {
- return 'success';
- }
- if($platformId != $sysPlatformId) {
- EmailQueue::rPush('柚子订单回传platformId与预期不符', json_encode([
- 'request_platform_id' => $platformId,
- 'sys_platform_id' => $sysPlatformId,
- 'desc' => '杭州猎豆'
- ]), ['song.shen@kuxuan-inc.com', 'xiaohua.hou@kuxuan-inc.com'], '猎羽');
- }
- // 查询app_id对应的token
- $conf = PlatformOrderConf::getTokenByPlatformId($platformId);
- if(empty($conf->token)) {
- return 'fail';
- }
- // 根据配置找到对应的系统账号组,用于在数据看板中区分订单所属账号
- $orderPay['sys_group_id'] = $conf->sys_group_id;
- // 数据校验
- $check = MsgService::checkSignature($nonce, $timestamp, $conf->token, $signature);
- if($check === false) {
- return 'fail';
- }
- try{
- // 将数据保存入数据库
- DjOrderService::youziOrderSave($orderPay, 1, 1, $platformId);
- } catch (\Exception $exception) {
- Log::logError('保存柚子订单数据异常', [
- 'params' => json_decode(json_encode($request->all()), 1),
- 'file' => $exception->getFile(),
- 'line' => $exception->getLine(),
- 'message' => $exception->getMessage(),
- 'trace' => $exception->getTraceAsString()], 'callBackOrderError');
- $this->exceptionHandler('callBackOrder', json_encode([
- 'err_msg' => '保存柚子订单数据异常',
- 'params' => json_decode(json_encode($request->all()), 1),
- 'file' => $exception->getFile(),
- 'line' => $exception->getLine(),
- 'message' => $exception->getMessage(),
- 'trace' => $exception->getTraceAsString(),
- ]));
- return 'fail';
- }
- return 'success';
- }
- // 嘉书平台 小程序订单
- public function jiashuOrderCallBack(Request $request)
- {
- $timestamp = $request->input('timestamp');
- $nonce = $request->input('nonce');
- $signature = $request->input('signature');
- $orderPay = $request->input('orderPay');
- $appId = '3a8vJ2t0K5XkH5Wl';
- // 将接收到的数据保存的日志文件中
- Log::logInfo(json_encode($request->all(), JSON_UNESCAPED_UNICODE), [], 'jiashuOrder');
- // 查询app_id对应的token
- $conf = PlatformOrderConf::getTokenByPlatformId($appId);
- if(empty($conf->token)) {
- return 'fail';
- }
- // 根据配置找到对应的系统账号组,用于在数据看板中区分订单所属账号
- $orderPay['sys_group_id'] = $conf->sys_group_id;
- // 数据校验
- $check = MsgService::checkSignature($nonce, $timestamp, $conf->token, $signature);
- if($check === false) {
- return 'fail';
- }
- try{
- DjOrderService::jiashuOrderSave($orderPay, $appId);
- } catch (\Exception $exception) {
- Log::logError('保存嘉书订单数据异常', [
- 'params' => json_decode(json_encode($request->all()), 1),
- 'file' => $exception->getFile(),
- 'line' => $exception->getLine(),
- 'message' => $exception->getMessage(),
- 'trace' => $exception->getTraceAsString()], 'callBackOrderError');
- $this->exceptionHandler('callBackOrder', json_encode([
- 'err_msg' => '保存嘉书订单数据异常',
- 'params' => json_decode(json_encode($request->all()), 1),
- 'file' => $exception->getFile(),
- 'line' => $exception->getLine(),
- 'message' => $exception->getMessage(),
- 'trace' => $exception->getTraceAsString(),
- ]));
- return 'fail';
- }
- return 'success';
- }
- # 迈步平台 小程序订单
- public function orderCallBack(Request $request)
- {
- $platformId = $request->input('platformId');
- $timestamp = $request->input('timestamp');
- $nonce = $request->input('nonce');
- $signature = $request->input('signature');
- $orderPay = $request->input('orderPay');
- // 将接收到的数据保存的日志文件中
- Log::logInfo(json_encode($request->all(), JSON_UNESCAPED_UNICODE), [], 'callBackOrder');
- // 查询app_id对应的token
- $conf = PlatformOrderConf::getTokenByPlatformId($platformId);
- if(empty($conf->token)) {
- return 'fail';
- }
- // 根据配置找到对应的系统账号组,用于在数据看板中区分订单所属账号
- $orderPay['sys_group_id'] = $conf->sys_group_id;
- // 数据校验
- $check = MsgService::checkSignatureNew($nonce, $timestamp, $conf->token, $platformId, $signature);
- if($check === false) {
- return 'fail';
- }
- try{
- DjOrderService::unifyOrderSave($orderPay, $platformId);
- } catch (\Exception $exception) {
- Log::logError('保存其他平台订单数据异常', [
- 'params' => json_decode(json_encode($request->all()), 1),
- 'file' => $exception->getFile(),
- 'line' => $exception->getLine(),
- 'message' => $exception->getMessage(),
- 'trace' => $exception->getTraceAsString()], 'callBackOrderError');
- $this->exceptionHandler('callBackOrder', json_encode([
- 'err_msg' => '保存其他平台订单数据异常',
- 'params' => json_decode(json_encode($request->all()), 1),
- 'file' => $exception->getFile(),
- 'line' => $exception->getLine(),
- 'message' => $exception->getMessage(),
- 'trace' => $exception->getTraceAsString(),
- ]));
- return 'fail';
- }
- return 'success';
- }
- public function exceptionHandler($key, $message)
- {
- $val = RedisModel::get($key);
- if(empty($val)) {
- EmailQueue::rPush('订单保存异常', $message, ['song.shen@kuxuan-inc.com'], []);
- RedisModel::set($key, 1);
- RedisModel::expire($key, 30*60);
- }
- }
- // 嘉书平台 H5订单
- public function jiashuWebOrderCallBack(Request $request)
- {
- // 将接收到的数据保存的日志文件中
- Log::logInfo(json_encode($request->all(), JSON_UNESCAPED_UNICODE), [], 'callBackOrderWeb');
- # 因为嘉书方不提供签名逻辑以及失败重试逻辑,因此要尽量保证该接口稳定
- try{
- DjOrderService::jiashuWebOrderSave($request->all());
- } catch (\Exception $exception) {
- Log::logError('保存嘉书H5订单数据异常', [
- 'params' => json_decode(json_encode($request->all()), 1),
- 'file' => $exception->getFile(),
- 'line' => $exception->getLine(),
- 'message' => $exception->getMessage(),
- 'trace' => $exception->getTraceAsString()], 'callBackOrderError');
- $this->exceptionHandler('callBackOrder', json_encode([
- 'err_msg' => '保存嘉书H5订单数据异常',
- 'params' => json_decode(json_encode($request->all()), 1),
- 'file' => $exception->getFile(),
- 'line' => $exception->getLine(),
- 'message' => $exception->getMessage(),
- 'trace' => $exception->getTraceAsString(),
- ]));
- return ['code' => '-1', 'message' => 'system error'];
- }
- return ['code' => 0, 'message' => 'ok'];
- }
- // 杭州剧有戏-柚子平台
- public function juyouxiYouziOrderCallBack(Request $request)
- {
- $msgType = $request->input('msgType');
- $timestamp = $request->input('timestamp');
- $nonce = $request->input('nonce');
- $signature = $request->input('signature');
- $orderPay = $request->input('orderPay');
- $platformId = $request->input('platformId');
- $sysPlatformId = 'mNUdMhDNC20CvYLe';
- if(empty($orderPay)) {
- // 在柚子端填写回调地址回调使用
- return 'success';
- }
- // 将接收到的数据保存的日志文件中
- Log::logInfo(json_encode($request->all(), JSON_UNESCAPED_UNICODE), [$platformId], 'youziOrder');
- if($msgType != 'orderPay') {
- return 'success';
- }
- if($platformId != $sysPlatformId) {
- EmailQueue::rPush('柚子订单回传platformId与预期不符', json_encode([
- 'request_platform_id' => $platformId,
- 'sys_platform_id' => $sysPlatformId,
- 'desc' => '剧有戏'
- ]), ['song.shen@kuxuan-inc.com', 'xiaohua.hou@kuxuan-inc.com'], '猎羽');
- }
- // 查询app_id对应的token
- $conf = PlatformOrderConf::getTokenByPlatformId($platformId);
- if(empty($conf->token)) {
- Log::logError('保存杭州剧有戏柚子订单数据异常', ['未查询到token'], 'orderTest');
- return 'fail';
- }
- // 根据配置找到对应的系统账号组,用于在数据看板中区分订单所属账号
- $orderPay['sys_group_id'] = $conf->sys_group_id;
- // 数据校验
- $check = MsgService::checkSignature($nonce, $timestamp, $conf->token, $signature);
- if($check === false) {
- Log::logError('保存杭州剧有戏柚子订单数据异常', ['数据校验失败'], 'orderTest');
- return 'fail';
- }
- try{
- // 将数据保存入数据库
- DjOrderService::youziOrderSave($orderPay, 1, 1, $platformId, 2);
- } catch (\Exception $exception) {
- Log::logError('保存杭州剧有戏柚子订单数据异常', [
- 'params' => json_decode(json_encode($request->all()), 1),
- 'file' => $exception->getFile(),
- 'line' => $exception->getLine(),
- 'message' => $exception->getMessage(),
- 'trace' => $exception->getTraceAsString()], 'callBackOrderError');
- $this->exceptionHandler('callBackOrder', json_encode([
- 'err_msg' => '保存杭州剧有戏柚子订单数据异常',
- 'params' => json_decode(json_encode($request->all()), 1),
- 'file' => $exception->getFile(),
- 'line' => $exception->getLine(),
- 'message' => $exception->getMessage(),
- 'trace' => $exception->getTraceAsString(),
- ]));
- return 'fail';
- }
- return 'success';
- }
- # 点众阳光
- public function platformOrderCallBack(Request $request)
- {
- $timestamp = $request->input('timestamp');
- $nonce = $request->input('nonce');
- $signature = $request->input('signature');
- $orderPay = $request->input('orderPay');
- $platformId = $request->input('platformId');
- // 将接收到的数据保存的日志文件中
- Log::logInfo(json_encode($request->all(), JSON_UNESCAPED_UNICODE), [$platformId], 'platformOrder');
- $taskId = $request->input('taskId', '');
- $xurl = $request->input('xurl', '');
- if(!empty($taskId)) {
- # 主动同步下来的订单
- return HttpService::httpGet('https://idea-ad.wenxingshuju.com/sunshine/orderList?'.http_build_query($request->all()));
- }
- // 查询app_id对应的token
- $conf = PlatformOrderConf::getTokenByPlatformId($platformId);
- if(empty($conf->token)) {
- Log::logError('保存订单数据异常', ['未查询到token'], 'platformOrder');
- return 'fail';
- }
- // 根据配置找到对应的系统账号组,用于在数据看板中区分订单所属账号
- $orderPay['sys_group_id'] = $conf->sys_group_id;
- $orderPay['order_source'] = $conf->order_source;
- $orderPay['platform_id'] = $platformId;
- // 数据校验
- $check = MsgService::checkSignatureNew($nonce, $timestamp, $conf->token, $platformId, $signature);
- if($check === false) {
- Log::logError('保存订单数据异常', ['数据校验失败'], 'platformOrder');
- return 'fail';
- }
- try{
- // 将数据保存入数据库
- DjOrderService::platformOrderCallBack($orderPay);
- } catch (\Exception $exception) {
- Log::logError('保存第三方订单数据异常', [
- 'params' => json_decode(json_encode($request->all()), 1),
- 'file' => $exception->getFile(),
- 'line' => $exception->getLine(),
- 'message' => $exception->getMessage(),
- 'trace' => $exception->getTraceAsString()], 'platformOrder');
- $this->exceptionHandler('callBackOrder', json_encode([
- 'err_msg' => '保存第三方订单数据异常',
- 'params' => json_decode(json_encode($request->all()), 1),
- 'file' => $exception->getFile(),
- 'line' => $exception->getLine(),
- 'message' => $exception->getMessage(),
- 'trace' => $exception->getTraceAsString(),
- ]));
- return 'fail';
- }
- return 'success';
- }
- # 接收容量平台用户和订单信息
- public function capacityUserCallBack(Request $request)
- {
- // 将接收到的数据保存的日志文件中
- Log::logInfo(json_encode($request->all(), JSON_UNESCAPED_UNICODE), [], 'CapacityUser');
- $platformId = $request->input('platformId');
- try{
- // 查询app_id对应的token
- $conf = PlatformOrderConf::getTokenByPlatformId($platformId);
- if(empty($conf->token)) {
- Log::logError('保存订单数据异常', ['未查询到token'], 'CapacityUserError');
- return json_encode($response = [
- 'code' => 1102,
- 'msg' => '',
- ]);
- }
- // 根据配置找到对应的系统账号组,用于在数据看板中区分订单所属账号
- $data = $request->all();
- $data['sys_group_id'] = $conf->sys_group_id;
- $data['order_source'] = $conf->order_source;
- $data['platform_id'] = $platformId;
- // 将数据保存入数据库
- list($code, $msg) = CapacityService::saveUserList($data);
- $response = [
- 'code' => $code,
- 'msg' => $msg,
- ];
- } catch (\Exception $exception) {
- Log::logError('保存容量用户数据异常', [
- 'params' => json_decode(json_encode($request->all()), 1),
- 'file' => $exception->getFile(),
- 'line' => $exception->getLine(),
- 'message' => $exception->getMessage(),
- 'trace' => $exception->getTraceAsString()], 'CapacityUserError');
- $this->exceptionHandler('callBackOrder', json_encode([
- 'err_msg' => '保存容量用户数据异常',
- 'params' => json_decode(json_encode($request->all()), 1),
- 'file' => $exception->getFile(),
- 'line' => $exception->getLine(),
- 'message' => $exception->getMessage(),
- 'trace' => $exception->getTraceAsString(),
- ]));
- $response = [
- 'code' => 1102,
- 'msg' => '',
- ];
- }
- return json_encode($response);
- }
- }
|