apiLink = config('app.USE_STAFF_API_LINK'); $this->accessId = config('app.USE_STAFF_ACCESS_ID'); $this->accessSecret = config('app.USE_STAFF_ACCESS_SECRET'); $this->groundAgentId = config('app.USE_STAFF_GROUND_AGENT_ID'); $this->bmemberId = config('app.USE_STAFF_BMEMBER_ID'); $this->coreAgentId = config('app.USE_STAFF_CORE_AGENT_ID'); $this->memberId = config('app.USE_STAFF_MEMBER_ID'); } /** * Common: 发起请求 - 请求接口 * Author: wu-hui * Time: 2023/10/08 15:46 * @param $api * @param $params * @return mixed|void */ private function requestApi($api,$params){ try{ // 获取签名 $sign = $this->getSign($params); // 发起请求 $data = [ 'jsonStr' => json_encode($params,JSON_UNESCAPED_UNICODE), 'sign' => $sign, ]; $header = [ 'Content-Type: application/json; charset=utf-8', 'Cache-Control: no-cache', 'Pragma: no-cache' ]; $result = curlPost($this->apiLink.$api,$data,30,$header,'json'); $result['jsonStr'] = json_decode($result['jsonStr'],true); return $result['jsonStr']; }catch(\Exception $e){ \Log::debug('------- 灵活务工 - 接口请求 - 失败原因 -----',$e->getMessage()); return $e->getMessage(); } } /** * Common: 发起请求 - 获取签名 * Author: wu-hui * Time: 2023/10/08 14:41 * @param $params * @return false|string */ private function getSign($params){ // 按照 key 的 ASCII 字符串顺序升序排列 ksort($params); // 获取签名字符串 $signStr = ''; foreach($params as $key => $val){ $signStr .= is_array($val) ? json_encode($val) : $val; } // 获取签名 return hash_hmac("sha256",$signStr,$this->accessSecret); } /** * Common: 根据方法名称 返回回调地址 * Author: wu-hui * Time: 2023/10/09 11:24 * @param $funName * @return string * @throws Exception */ private function getNotifyUrl($funName){ // 异步通知地址前缀 $domainName = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http"; $domainName .= "://" . $_SERVER['HTTP_HOST']; $uniacid = \YunShop::app()->uniacid; // 回调地址长度不能超过100 $notifyUrl = $domainName."/addons/yun_shop/api.php?i={$uniacid}&route=plugin.use-staff.api.notify.".$funName; if(strlen($notifyUrl) > 100) throw new \Exception('异步通知地址长度超出限制,请联系管理员处理'); return $notifyUrl; } /** * Common: 员工入驻 - 申请入驻 * Author: wu-hui * Time: 2023/10/08 16:58 * @param $info * @return mixed|void * @throws Exception */ public function personnelAccess($info){ // 基本参数 $params = [ 'accessId' => $this->accessId,// [必填]接入ID 'orderId' => createNo('YCH',6,TRUE),// [必填]请求流水号 'coreAgentId' => $this->coreAgentId,// [必填]核心企业机构号 'groundAgentId' => $this->groundAgentId,// [必填]落地公司机构号 'noticeUrl' => $this->getNotifyUrl('access'),// [必填]异步通知地址 'name' => $info['name'],// [必填]账户名称 // 'jobNum' => '',// [选填]工号 'contactTelNo' => $info['tel'],// [必填]手机号 // 'bankProvId' => '510000',// [必填]银行所在省 // 'bankCityId' => '510100',// [必填]银行所在市 'cardType' => $info['card_type'],// [必填]卡类型(1-对私/2-对公) // 'bankName' => '',// [选填]银行名称 'bankSubName' => $info['bank_sub_name'] ?? '',// [条件必填]开户银行支行名称,卡类型为2-对公必填 'accountIdSdate' => $info['account_id_start'],// [必填]证件有效期开始时间 // 'accountIdEdate' => '20401107',// [选填]证件有效期终止时间,YYYYMMDD或长期 'bankActName' => $info['bank_act_name'],// [必填]卡号姓名 'cardNum' => $info['card_num'],// [必填]卡号 'accountIdNo' => $info['account_id'],// [必填]持卡人证件号 'accountIdType' => '1',// [选填]证件类型(1.身份证 9.其他类型)不填默认1 'merType' => $info['mer_type'],// [必填]商户类型 (1-个体户/3-个人) // 'merName' => '',// [条件必填]商户注册名称 // 'merShortName' => '',// [条件必填]商户简称 // 'provId' => '',// [条件必填]商户经营所在省 // 'cityId' => '',// [条件必填]商户经营所在市 // 'areaId' => '',// [条件必填]商户经营所在区县 // 'merAddress' => '',// [条件必填]商户经营地址 // 'businessCode' => '',// [条件必填]营业执照号 // 'businessSdate' => '',// [条件必填]营业执照有效期开始日期 // 'businessEdate' => '',// [条件必填]营业执照有效期结束日期,YYYYMMDD或长期 ]; // 发起请求 $result = $this->requestApi('/api/personnel/personnelAccess',$params); $result['memberId'] = ''; if((int)$result['respCode'] === 0) { $params['uid'] = $info['uid']; $params['memberId'] = $result['memberId']; $params['trans_seq_id'] = $result['transSeqId']; $params['status'] = $result['state']; // 判断:当前用户是否已经存在账号信息 $isHas = (int)UseStaff::uniacid()->where('uid',$info['uid'])->value('id'); if($isHas > 0) (new UseStaff())->updateRecord($params); else (new UseStaff())->addRecord($params); return $result; }else throw new Exception($result['respDesc']); } /** * Common: 员工入驻 - 入驻结果查询 * Author: wu-hui * Time: 2023/10/08 17:02 * @param $memberId * @param $transSeqId * @return mixed|void * @throws Exception */ public function personnelResult($memberId = '',$transSeqId = ''){ // 基本参数 $params = [ 'accessId' => $this->accessId,// [必填]接入ID 'transSeqId' => $transSeqId,// [选填]系统流水号 'memberId' => $memberId,// [选填]会员号 ]; // 发起请求 $result = $this->requestApi('/api/personnel/queryPersonnel',$params); if((int)$result['respCode'] === 0) { UseStaff::uniacid()->where('member_id',$memberId)->update([ 'status' => $result['state'], 'member_id' => $result['memberId'] ]); return $result; }else throw new Exception($result['respDesc']); } /** * Common: 员工签约 * Author: wu-hui * Time: 2023/10/08 17:46 * @param $uid * @return mixed|void * @throws Exception */ public function personalContractCreate($uid){ // 获取员工信息 $staff = UseStaff::getSingleInfo(['uid'=>$uid]); // 基本参数 $params = [ 'accessId' => $this->accessId,// [必填]接入ID 'orderId' => createNo('YCH',4,TRUE),// [必填]请求流水号 'coreAgentId' => $this->coreAgentId,// [必填]核心企业机构号 'groundAgentId' => $this->groundAgentId,// [必填]落地公司机构号 'memberId' => $staff['member_id'],// [必填]个人会员号 'signResultViewUrl' => '',// [选填]签约结果提示显示页面 ]; // 发起请求 $result = $this->requestApi('/api/contract/personalContractCreate',$params); if((int)$result['respCode'] === 0) { UseStaff::uniacid()->where('member_id',$staff['member_id'])->update([ 'signing_status' => $result['signState'], 'contract_id' => $result['contractId'], 'contract_name' => $result['contractName'], ]); return $result; }else throw new Exception($result['respDesc']); } /** * Common: 员工签约 - 签约结果查询 * Author: wu-hui * Time: 2023/10/08 17:50 * @param $memberId * @return mixed|void * @throws Exception */ public function personalContractQuery($memberId){ // 获取员工信息 $staff = UseStaff::getSingleInfo(['member_id'=>$memberId]); // 基本参数 $params = [ 'accessId' => $this->accessId,// [必填]接入ID 'orderId' => createNo('YCH',6,TRUE),// [必填]请求流水号 'contractId' => $staff['contract_id'],// [必填]核心企业机构号 ]; // 发起请求 $result = $this->requestApi('/api/contract/personalContractQuery',$params); if((int)$result['respCode'] === 0) { UseStaff::uniacid()->where('member_id',$staff['member_id'])->update([ 'signing_status' => $result['signState'], ]); return $result; }else throw new Exception($result['respDesc']); } /** * Common: 费用代发 - 申请代发 * Author: wu-hui * Time: 2023/10/09 10:15 * @param $info * @return mixed|void * @throws Exception */ public function salaryModelOutOrder($info){ // 获取员工信息 $staff = UseStaff::getSingleInfo($info); // 基本参数 $orderNo = createNo('YCH',6,TRUE); $params = [ 'accessId' => $this->accessId,// [必填]接入ID 'orderId' => $orderNo,// [必填]请求流水号 'agentId' => $this->coreAgentId,// [必填]核心企业机构号 'bmemberId' => $this->bmemberId,// [必填]落地公司商户号,落地公司memberId 'salaryModle' => '1',// [必填]代发模式,1-普票 2-专票 'accountModle' => '2',// [必填]走账模式,2-代发 'modeIdcompany' => '1',// [必填]走账类型,1-单账户模式 'noticeUrl' => $this->getNotifyUrl('salary'),// [必填]异步通知地址 // [必填]代发费用明细 'batchSalaryOutOrderModleDtos' => [[ 'memberId' => $staff['member_id'],// [必填]会员号 'outOrderId' => $orderNo,// [必填]外部订单号 'salary' => $info['salary'],// [必填]费用金额 'salaryMonth' => $info['month'],// [必填]月份,格式:YYYYMM ]], ]; // 发起请求 $result = $this->requestApi('/api/salaryInfo/salaryModleOutOrder',$params); if((int)$result['respCode'] === 2) { $time = time(); UseStaffSalary::insert([ 'uniacid' => \YunShop::app()->uniacid, 'uid' => $info['uid'], 'order_no' => $orderNo, 'member_id' => $staff['member_id'], 'salary' => $info['salary'], 'salary_month' => $info['month'], 'attach_id' => $result['attachId'], 'created_at' => $time, 'updated_at' => $time, ]); return $result; }else throw new Exception($result['respDesc']); } /** * Common: 费用代发 - 结果查询 * Author: wu-hui * Time: 2023/10/09 10:51 * @param $attachId * @return mixed|void * @throws Exception */ public function salaryOutOrderResult($attachId){ // 基本参数 $params = [ 'accessId' => $this->accessId,// [必填]接入ID 'memberId' => $this->memberId,// [必填]智汇管家代理商会员号 'attachId' => $attachId,// [条件必填]若订单号未填,则批次号必填 // 'orderId' => $this->accessId,// [条件必填]若批次号未填,则订单号必填 ]; // 发起请求 $result = $this->requestApi('/api/queryresult/salaryOutOrderResult',$params); if((int)$result['respCode'] === 0) { $salaryOutOrderRespDto = $result['salaryOutOrderRespDto']; $first = collect($salaryOutOrderRespDto)->first(); UseStaffSalary::where('attach_id',$attachId) ->update([ 'attach_state' => $result['attachState'], 'order_amt' => $first['orderAmt'], 'real_trans_amt' => $first['realTransAmt'], 'out_member_id' => $first['outMemberId'], 'salary_state' => $first['salaryState'], 'trans_fee' => $first['transFee'], ]); return $result; }else throw new Exception($result['respDesc']); } public function test(){ debug([ '灵活用工配置信息', '请求地址' => $this->apiLink, // '接入ID' => $this->accessId, // '请求密钥' => $this->accessSecret, // '落地公司机构号' => $this->groundAgentId, // '落地公司商户号' => $this->bmemberId, // '核心企业机构号' => $this->coreAgentId, // '核心企业商户号' => $this->memberId, ]); } }