Bladeren bron

no message

panghu 1 jaar geleden
bovenliggende
commit
3c14c13871

+ 78 - 0
app/Http/Controllers/AdminApi/MemberController.php

@@ -0,0 +1,78 @@
+<?php
+
+namespace App\Http\Controllers\AdminApi;
+
+use App\Http\Controllers\AdminController;
+use App\Models\Member;
+use App\Servers\ESign\ESignServer;
+use App\Servers\System\CommonServer;
+
+class MemberController extends AdminController
+{
+    /**
+     * 获取用户列表
+     * @return \Illuminate\Http\JsonResponse
+     */
+    function getMemberList(){
+
+        $where = [['is_del',0]];
+
+        $list = Member::where($where)
+            ->select(['id','name','phone','id_number','psnId','realnameStatus','authorizeUserInfo','created_at'])
+            ->paginate(10);
+        return $this->apiResponseSuccess('获取列表成功', [
+            'items' => $list->items(),
+            'total' => $list->total(),
+            'limit' => 10,
+        ]);
+    }
+
+    /**
+     * 添加&编辑用户
+     * @return \Illuminate\Http\JsonResponse
+     * @throws \Throwable
+     */
+    function saveMember(){
+
+        $id=request()->input('id','');//id
+        $name=request()->input('name','');//姓名
+        $phone=request()->input('phone','');//电话
+        $id_number=request()->input('id_number','');//身份证号
+        if (empty($name)) return $this->apiResponseError('请填写姓名');
+        if (mb_strlen($name) > 100) return $this->apiResponseError('姓名最大100');
+
+        if (empty($phone)) return $this->apiResponseError('请填写手机号');
+        if (!CommonServer::creatServer()->verifyPhoneNumber($phone)) return $this->apiResponseError('手机号错误');
+        if (empty($id_number)) return $this->apiResponseError('请填写身份证号');
+
+        //检查该身份证号是否存在
+        $member = Member::where('id_number',$id_number)->where('is_del',0)->select(['id'])->first();
+        if (!empty($member)){
+            return $this->apiResponseError('身份证号已存在');
+        }
+        $authType = 'PSN';
+        $data = compact('name','phone','id_number','authType');
+
+        if(empty($id)){//不存在id就创建
+
+            $res = Member::create($data);
+        }else{//存在就更新
+            $info = Member::where('id',$id)->select(['id'])->first();
+            if (empty($info)) {
+                return $this->apiResponseError('没有找到该记录');
+            }
+            $res = $info->update($data);
+        }
+        $m_id = $res->{'id'};
+        //查询个人认证信息
+        ESignServer::creatServer()->personsidentityinfo($m_id,$phone,$name,$id_number);
+
+
+        if ($res) {
+            return $this->apiResponseSuccess('操作成功');
+        } else {
+            return $this->apiResponseError('操作失败');
+        }
+    }
+
+}

+ 77 - 0
app/Http/Controllers/AdminApi/NotifyController.php

@@ -0,0 +1,77 @@
+<?php
+
+namespace App\Http\Controllers\AdminApi;
+
+
+use App\Http\Controllers\ApiController;
+use App\Models\Member;
+use App\Servers\ESign\comm\EsignLogHelper;
+
+class NotifyController extends ApiController
+{
+
+    /**
+     * e签宝回调通知
+     * @return false|string
+     */
+    function esignNotify()
+    {
+        $data = file_get_contents('php://input');
+        EsignLogHelper::writeLog($data,3);
+        $data = json_decode($data,true);
+        //回调错误
+        if (!isset($data['action'])){
+            return json_encode(['code'=>'0','msg'=>'error']);
+        }
+        if ($data['action'] == 'AUTH_PASS'){//实名认证通过通知
+            $authFlowId = $data['authFlowId'];
+
+            if ($data['authType'] == 'PSN'){
+                $psnId = $data['psnInfo']['psnId'];
+                //更新数据
+                $info = Member::where('authType','PSN')
+                    ->where('authFlowId',$authFlowId)
+                    ->update(['realnameStatus'=>1,'psnId'=>$psnId]);
+
+            }elseif ($data['authType'] == 'ORG'){
+                $orgId = $data['organization']['orgId'];
+                $orgName = $data['organization']['orgName'];
+                //更新数据
+                $info = Firm::where('authType','ORG')
+                    ->where('firm_name',$orgName)
+                    ->where('realnameStatus',0)
+                    ->update(['realnameStatus'=>1,'orgId'=>$orgId]);
+
+            }
+
+        }elseif ($data['action'] == 'AUTHORIZE_FINISH'){//授权通知
+            $authFlowId = $data['authFlowId'];
+            $psnId = $data['psnId'];
+            $orgId = $data['orgId'] ?? '';
+            $authorizedInfo = json_encode($data['authorizedInfo']);
+            //更新用户授权数据
+            Member::where('authFlowId',$authFlowId)->update(['authorizeUserInfo'=>1,'realnameStatus'=>1,'psnId'=>$psnId,'orgId'=>$orgId,'authorizedInfo'=>$authorizedInfo]);
+            if($orgId){
+                //检查该企业是否认证授权
+                ESignFirmServer::creatServer()->setSignFirm($data);
+            }
+
+
+        }elseif ($data['action'] == 'AUTHORIZE_CHANGE'){
+            //授权变更通知
+
+        }elseif ($data['action'] == 'SIGN_FLOW_COMPLETE'){
+            //合同签署
+            ContractServer::creatServer()->signEnd($data['signFlowStatus'],$data['signFlowId']);
+        }elseif ($data['action'] == 'SIGN_MISSON_COMPLETE'){
+            //合同签署
+            if(!empty($data['organization']) && !empty($data['signFlowId']))ContractServer::creatServer()->signFirmEnd($data['signResult'],$data['signFlowId'],$data['organization']);
+        }elseif ($data['action']=='SEAL_AUTH_SIGN'){
+//            SealServer::creatServer()->sealNotify($data['authStatus'],$data['sealAuthBizId']);
+        }
+
+        return json_encode(['code'=>'200','msg'=>'success']);
+    }
+
+
+}

+ 1 - 0
app/Http/Middleware/AdminAuthMiddleware.php

@@ -15,6 +15,7 @@ class AdminAuthMiddleware
         'adminApi.auth.retrieve',//忘记密码
         'adminApi.common.send',
         'adminApi.auth.retrieve',
+        'adminApi.notify.esignNotify'
     ];
     /**
      * Handle an incoming request.

+ 30 - 0
app/Models/Member.php

@@ -0,0 +1,30 @@
+<?php
+
+namespace App\Models;
+
+use DateTimeInterface;
+use Illuminate\Database\Eloquent\Factories\HasFactory;
+use Illuminate\Database\Eloquent\Model;
+
+/**
+ * App\Models
+ *
+ * @mixin \Eloquent
+ */
+class Member extends Model
+{
+    use HasFactory;
+    protected $guarded = ['id', 'updated_at', 'created_at'];
+
+
+    /**
+     * 为数组 / JSON 序列化准备日期。
+     *
+     * @param \DateTimeInterface $date
+     * @return string
+     */
+    protected function serializeDate(DateTimeInterface $date)
+    {
+        return $date->format($this->dateFormat ?: 'Y-m-d H:i:s');
+    }
+}

+ 12 - 169
app/Servers/ESign/ESignServer.php

@@ -6,11 +6,9 @@ namespace App\Servers\ESign;
 
 
 use App\Models\Member;
-use App\Models\SignMember;
 use App\Servers\ESign\comm\EsignHttpHelper;
 use App\Servers\ESign\comm\EsignLogHelper;
 use App\Servers\ESign\emun\HttpEmun;
-use App\Servers\Member\MemberServer;
 use App\Servers\System\RedisDataServer;
 use App\Servers\System\SmsServer;
 
@@ -60,7 +58,7 @@ class ESignServer
      * 获取个人认证&授权页面链接
      * @return bool
      */
-    function psnauthurl($m_id,$firm_id,$phone,$psnName,$id_number,$psnId='')
+    function psnauthurl($m_id,$phone,$psnName,$id_number,$psnId='')
     {
         $authShortUrl=RedisDataServer::creatServer()->getData($m_id.'_memberUrl');
         if($authShortUrl){
@@ -87,7 +85,7 @@ class ESignServer
             "redirectConfig"=>[
                 "redirectUrl"=>'',
             ],
-            "notifyUrl"=>route('wps.esignNotify'),
+            "notifyUrl"=>route('notify.esignNotify'),
             "clientType"=>"ALL",
             "appScheme"=>""
         ];
@@ -103,15 +101,14 @@ class ESignServer
             if($authShortUrl){
                 return true;
             }
-            $signMember=SignMember::where('m_id',$m_id)->where('firm_id',$firm_id)->where('authType','PSN')->where([['updated_at','<=',date('Y-m-d H:i:s',time()-600),'or'],['authShortUrl','=','','or']])->first();
+            $signMember=Member::where('m_id',$m_id)->where('authType','PSN')->where([['updated_at','<=',date('Y-m-d H:i:s',time()-600),'or'],['authShortUrl','=','','or']])->first();
             if($signMember){
                 $authUrl = $ret['data']['authUrl'];
                 $authShortUrl = $ret['data']['authShortUrl'];
                 RedisDataServer::creatServer()->setData($m_id.'_memberUrl',$authShortUrl,'str',600);
                 $authFlowId = $ret['data']['authFlowId'];
-                $member=Member::where('id',$m_id)->select(['phone','promissory_name'])->first();
-                $content='尊敬的'.$member['promissory_name'].',您有待认证信息,点击认证 '.$authShortUrl;
-                 SmsServer::creatServer()->sendContent($member['phone'],$content);
+                $content='尊敬的'.$signMember['name'].',您有待认证信息,点击认证 '.$authShortUrl;
+                 SmsServer::creatServer()->sendContent($signMember['phone'],$content);
                 //存入数据库
                 $signMember->update([
                     'authUrl'=>$authUrl,
@@ -128,36 +125,16 @@ class ESignServer
 
     /**
      * 查询个人认证信息
-     * @param $m_id //用户id
-     * @param $firm_id //企业id
-     * @param $firm_name //企业名称
      * @param $phone //手机号
      * @param $psnName //认证人姓名
      * @param $id_number //认证人身份证号
      * @return SignMember|\Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model|object|null
      */
-    function personsidentityinfo($m_id,$firm_id,$firm_name,$phone,$psnName,$id_number)
+    function personsidentityinfo($m_id,$phone,$psnName,$id_number)
     {
-        $info =  SignMember::where('id_number',$id_number)->where('firm_id',$firm_id)->where('authType','PSN')->first();
-        if (empty($info)){
-            //入库
-            SignMember::create([
-                'm_id' => $m_id,
-                'firm_id' => $firm_id,
-                'firm_name' => $firm_name,
-                'phone' => $phone,
-                'name' => $psnName,
-                'id_number' => $id_number,
-                'realnameStatus'=>0,
-                'authorizeUserInfo'=>0,
-                'psnId'=>'',
-                'authShortUrl'=>'',
-                'authType' => 'PSN',
-            ]);
-        }else{
-            if($info->{'realnameStatus'}==1 && $info->{'psnId'}!=''){
-                return $info->{'realnameStatus'};
-            }
+        $info =  Member::where('id_number',$id_number)->where('id',$m_id)->where('authType','PSN')->first();
+        if($info->{'realnameStatus'}==1 && $info->{'psnId'}!=''){
+            return $info->{'realnameStatus'};
         }
 
         $config=$this->config;
@@ -175,17 +152,14 @@ class ESignServer
             //个人账号ID
             $psnId = $ret['data']['psnId'];
             //更新认证信息
-            SignMember::where('id_number',$id_number)->where('firm_id',$firm_id)->where('authType','PSN')->update([
+            Member::where('id_number',$id_number)->update([
                 'realnameStatus'=>$realnameStatus,
                 'authorizeUserInfo'=>$authorizeUserInfo,
                 'psnId'=>$psnId,
             ]);
-            if ($realnameStatus == 1){//更新用户认证状态
-                MemberServer::creatServer()->updateMemberStatus($m_id,$firm_id);
-            }
 
             if (empty($realnameStatus) || empty($authorizeUserInfo)){//走个人认证授权流程
-                $this->psnauthurl($m_id,$firm_id,$phone,$psnName,$id_number,$psnId);
+                $this->psnauthurl($m_id,$phone,$psnName,$id_number,$psnId);
             }
             //未授权也注销
             if(empty($authorizeUserInfo))$realnameStatus=0;
@@ -197,7 +171,7 @@ class ESignServer
             //个人账号ID
             $psnId = '';
             //走认证授权流程
-            $this->psnauthurl($m_id,$firm_id,$phone,$psnName,$id_number);
+            $this->psnauthurl($m_id,$phone,$psnName,$id_number);
         }
 
 
@@ -205,137 +179,6 @@ class ESignServer
         return $realnameStatus;
     }
 
-    /**
-     * 查询企业授权详情
-     * @param $orgId
-     * @return \App\Servers\ESign\comm\EsignResponse
-     */
-    function organizationsAuthorizedInfo($orgId){
-        $config=$this->config ;
-        $apiaddr="/v3/organizations/".$orgId."/authorized-info";
-        $requestType = HttpEmun::GET;
-        $signAndBuildSignAndJsonHeader = EsignHttpHelper::signAndBuildSignAndJsonHeader($config['eSignAppId'], $config['eSignAppSecret'], "", $requestType, $apiaddr);
-        //发起接口请求
-        EsignLogHelper::printMsg($signAndBuildSignAndJsonHeader);
-        $response = EsignHttpHelper::doCommHttp($config['eSignHost'], $apiaddr, $requestType, $signAndBuildSignAndJsonHeader, "");
-        EsignLogHelper::printMsg($response->getStatus());
-        EsignLogHelper::printMsg($response->getBody());
-        return $response;
-    }
-
-    /**
-     * 查询企业实名状态
-     * @param $orgName
-     * @return mixed
-     */
-    function organizationsIdentityInfo($orgName){
-         $config=$this->config;
-        $apiaddr="/v3/organizations/identity-info?orgName=".$orgName;
-        $requestType = HttpEmun::GET;
-        $signAndBuildSignAndJsonHeader = EsignHttpHelper::signAndBuildSignAndJsonHeader($config['eSignAppId'], $config['eSignAppSecret'], "", $requestType, $apiaddr);
-        //发起接口请求
-//        EsignLogHelper::printMsg($signAndBuildSignAndJsonHeader);
-        $response = EsignHttpHelper::doCommHttp($config['eSignHost'], $apiaddr, $requestType, $signAndBuildSignAndJsonHeader, "");
-//        EsignLogHelper::writeLog($response->getStatus());
-//        EsignLogHelper::printMsg($response->getBody());
-        $ret=json_decode($response->getBody(),true);
-        if(isset($ret['code']) && $ret['code']==0){
-            //realnameStatus 0 - 未实名,1 - 已实名
-            return $ret['data'];
-        }else{
-            return ['realnameStatus'=>-1,'orgId'=>'','authorizeUserInfo'=>false,'orgName'=>$orgName];
-        }
-    }
-
-    /**
-     * 获取机构认证&授权页面链接
-     * @param $orgName
-     */
-    function orgAuthUrl($orgName){
-        $config=$this->config;
-        $apiaddr="/v3/org-auth-url";
-        $requestType = HttpEmun::POST;
-        $data=[
-            "orgAuthConfig"=>[
-                "orgName"=>$orgName,
-                "orgInfo"=>[
-                    "orgIDCardNum"=>"",
-                    "orgIDCardType"=>"CRED_ORG_USCC"
-
-                ],
-                "transactorInfo"=>[
-                    "psnAccount"=>"",
-                    "psnInfo"=>[
-                        "psnIDCardNum"=>"",
-                        "psnName"=>""
-                    ]
-                ],
-            ],
-            "redirectConfig"=>[
-                "redirectUrl"=>"https://www.baidu.com/"
-            ],
-            "notifyUrl"=>"",
-            "clientType"=>"ALL",
-            "appScheme"=>""
-        ];
-        $paramStr = json_encode($data);
-        //生成签名验签+json体的header
-        $signAndBuildSignAndJsonHeader = EsignHttpHelper::signAndBuildSignAndJsonHeader($config['eSignAppId'], $config['eSignAppSecret'], $paramStr, $requestType, $apiaddr);
-        //发起接口请求
-//        EsignLogHelper::printMsg($signAndBuildSignAndJsonHeader);
-        $response = EsignHttpHelper::doCommHttp($config['eSignHost'], $apiaddr, $requestType, $signAndBuildSignAndJsonHeader, $paramStr);
-//        EsignLogHelper::printMsg($response->getStatus());
-//        EsignLogHelper::printMsg($response->getBody());
-    }
-
-    /**
-     * 企业授权
-     * @param $orgName
-     */
-    function orgAuthorizehUrl($orgName){
-        $config=$this->config;
-        $apiaddr="/v3/org-auth-url";
-        $requestType = HttpEmun::POST;
-        $data=[
-            "orgAuthConfig"=>[
-                "orgName"=>$orgName,
-                "orgInfo"=>[
-                    "orgIDCardNum"=>"",
-                    "orgIDCardType"=>" "
-
-                ],
-                "transactorInfo"=>[
-                    "psnAccount"=>"",
-                    "psnInfo"=>[
-                        "psnIDCardNum"=>"",
-                        "psnName"=>""
-                    ]
-                ],
-            ],
-            "authorizeConfig"=>[
-                "authorizedScopes"=>[
-                    "get_org_identity_info","get_psn_identity_info","org_initiate_sign","psn_initiate_sign","manage_org_resource","manage_psn_resource","use_org_order"
-                ]
-            ],
-            "redirectConfig"=>[
-                "redirectUrl"=>"https://www.baidu.com/"
-            ],
-            "notifyUrl"=>"",
-            "clientType"=>"ALL",
-            "appScheme"=>""
-        ];
-        $paramStr = json_encode($data);
-        //生成签名验签+json体的header
-        $signAndBuildSignAndJsonHeader = EsignHttpHelper::signAndBuildSignAndJsonHeader($config['eSignAppId'], $config['eSignAppSecret'], $paramStr, $requestType, $apiaddr);
-        //发起接口请求
-        EsignLogHelper::printMsg($signAndBuildSignAndJsonHeader);
-        $response = EsignHttpHelper::doCommHttp($config['eSignHost'], $apiaddr, $requestType, $signAndBuildSignAndJsonHeader, $paramStr);
-        EsignLogHelper::printMsg($response->getStatus());
-        EsignLogHelper::printMsg($response->getBody());
-    }
-
-
-
 
 
 

+ 13 - 0
routes/adminApi/notify.php

@@ -0,0 +1,13 @@
+<?php
+
+use Illuminate\Support\Facades\Route;
+
+
+Route::group( ['domain' => env('APP_ADMIN_HOST'), 'prefix' => 'notify'],function($router){
+
+
+    Route::match(['post','get'],'esignNotify', 'NotifyController@esignNotify')->name('adminApi.notify.esignNotify');
+
+});
+
+