NotifyController.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. namespace App\Http\Controllers\AdminApi;
  3. use App\Http\Controllers\ApiController;
  4. use App\Models\Firm;
  5. use App\Models\Member;
  6. use App\Models\SignContract;
  7. use App\Models\SignRecord;
  8. use App\Servers\ESign\comm\EsignLogHelper;
  9. use App\Servers\System\JobServer;
  10. class NotifyController extends ApiController
  11. {
  12. /**
  13. * e签宝回调通知
  14. * @return false|string
  15. */
  16. function esignNotify()
  17. {
  18. $data = file_get_contents('php://input');
  19. EsignLogHelper::writeLog($data,3);
  20. $data = json_decode($data,true);
  21. //回调错误
  22. if (!isset($data['action'])){
  23. return json_encode(['code'=>'0','msg'=>'error']);
  24. }
  25. if ($data['action'] == 'AUTH_PASS'){//实名认证通过通知
  26. $authFlowId = $data['authFlowId'];
  27. if ($data['authType'] == 'PSN'){
  28. $psnId = $data['psnInfo']['psnId'];
  29. //更新数据
  30. $info = Member::where('authType','PSN')
  31. ->where('authFlowId',$authFlowId)
  32. ->update(['realnameStatus'=>1,'psnId'=>$psnId]);
  33. }elseif ($data['authType'] == 'ORG'){
  34. $orgId = $data['organization']['orgId'];
  35. $orgName = $data['organization']['orgName'];
  36. //更新数据
  37. $info = Firm::where('authType','ORG')
  38. ->where('firm_name',$orgName)
  39. ->where('realnameStatus',0)
  40. ->update(['realnameStatus'=>1,'orgId'=>$orgId]);
  41. }
  42. }elseif ($data['action'] == 'AUTHORIZE_FINISH'){//授权通知
  43. $authFlowId = $data['authFlowId'];
  44. $psnId = $data['psnId'];
  45. $orgId = $data['orgId'] ?? '';
  46. $authorizedInfo = json_encode($data['authorizedInfo']);
  47. if($orgId){
  48. Firm::where('authFlowId',$authFlowId)->update(['authorizeUserInfo'=>1,'realnameStatus'=>1,'orgId'=>$orgId,'authorizedInfo'=>$authorizedInfo]);
  49. //检测系统内部的企业印章信息
  50. // JobServer::creatServer()->createFirmSealJob($orgId);
  51. }else{
  52. Member::where('authFlowId',$authFlowId)->update(['authorizeUserInfo'=>1,'realnameStatus'=>1,'psnId'=>$psnId,'authorizedInfo'=>$authorizedInfo]);
  53. //检测系统内部的企业印章信息
  54. // JobServer::creatServer()->createMemberSealJob($psnId);
  55. }
  56. }elseif ($data['action'] == 'AUTHORIZE_CHANGE'){
  57. //授权变更通知
  58. }elseif ($data['action'] == 'SIGN_FLOW_COMPLETE'){
  59. //合同签署
  60. $signFlowStatus = $data['signFlowStatus'];
  61. $signFlowId = $data['signFlowId'];
  62. SignContract::where('flow_id',$signFlowId)->update(['status'=>$signFlowStatus]);
  63. }elseif ($data['action'] == 'SIGN_MISSON_COMPLETE'){
  64. // file_put_contents('sign_misson_complete.txt', json_encode($data));
  65. //合同签署
  66. $signFlowStatus = $data['signResult'];
  67. $signFlowId = $data['signFlowId'];
  68. $organization = isset($data['organization']) ? $data['organization'] : '';
  69. $operator = $data['operator'];
  70. if (!empty($signFlowId)){
  71. $sign = SignContract::where('flow_id',$signFlowId)->first();
  72. $sign_id = $sign->{'id'};
  73. if (!empty($operator) && empty($organization)){//个人签署回调没有$organization信息
  74. $psnId = $operator['psnId'];
  75. // SignRecord::where('sign_id',$sign_id)->where('authType','PSN')->where('id_no',$psnId)->update(['status'=>$signFlowStatus]);
  76. SignRecord::where('sign_id',$sign_id)->where('authType','PSN')->update(['status'=>$signFlowStatus]);
  77. }
  78. if (!empty($organization)){
  79. $orgId = $organization['orgId'];
  80. // SignRecord::where('sign_id',$sign_id)->where('authType','ORG')->where('id_no',$orgId)->update(['status'=>$signFlowStatus]);
  81. SignRecord::where('sign_id',$sign_id)->where('authType','ORG')->update(['status'=>$signFlowStatus]);
  82. }
  83. }
  84. }elseif ($data['action']=='SEAL_AUTH_SIGN'){
  85. // SealServer::creatServer()->sealNotify($data['authStatus'],$data['sealAuthBizId']);
  86. }
  87. return json_encode(['code'=>'200','msg'=>'success']);
  88. }
  89. }