| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- <?php
- namespace App\Jobs;
- use App\Repositories\ConfigRepoistory;
- use Hyperf\AsyncQueue\Job;
- use Hyperf\Guzzle\ClientFactory;
- /**
- * 代理系统用户登陆
- */
- class AgentUserLoginJob extends Job
- {
- public $params;
- public function __construct($params)
- {
- // 这里最好是普通数据,不要使用携带 IO 的对象,比如 PDO 对象
- $this->params = $params;
- }
- public function handle()
- {
- $agentConf = make(ConfigRepoistory::class)->pickByKeys(['agent_url', 'app_uid', 'agent_token'], 'sys');
- $url = $agentConf['agent_url']['svalue'] . 'user/login';
- $data = [
- [
- 'channel_uid' => $this->params['channel_id'],
- 'created_at' => $this->params['created_at'],
- 'device_type' => $this->params['device_type'],
- 'mom_app_uid' => $agentConf['app_uid']['svalue'],
- 'user_uid' => $this->params['code'],
- 'app_version' => $this->params['version'],
- 'device_no' => $this->params['device_no']
- ]
- ];
- $options = array(
- 'timeout' => 20, // 超时,单位秒.
- 'verify' => false, // 是否校验SSL证书.
- 'http_errors' => false, // 如果跟随http异常头部是否中断.
- 'debug' => false, // 是否启用调试模式.
- 'allow_redirects' => true, // 不跟随301/302跳转.
- );
- $client = make(ClientFactory::class)->create($options);
- try {
- $params = [
- 'headers' => [
- 'Content-Type'=>'application/json',
- 'X-TOKEN' => $agentConf['agent_token']['svalue']
- ],
- 'json'=>$data,
- ];
- $result = $client->post($url, $params);
- $code = $result->getStatusCode();
- if ($code == 200) {
- return $result->getBody()->getContents();
- } else {
- logger('AgentUserLoginJob', ['代理系统登陆失败', $data]);
- }
- } catch (\Exception $exception) {
- logger('AgentUserLoginJob', [$exception->getMessage(), $data]);
- }
- // 异步处理该用户的系统消息分配给用户消息.
- dispatch_job(new InitSysMessageJob(['receive_uid' => $this->params['code']]));
- }
- }
|