love_php/app/Jobs/UpdateWechatUserInfo.php

63 lines
2.0 KiB
PHP
Raw Permalink Normal View History

2026-04-02 09:20:51 +08:00
<?php
namespace App\Jobs;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Support\Facades\Cache;
use App\Models\Participant;
class UpdateWechatUserInfo implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
protected $participant;
public $tries = 1;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct($participant)
{
$this->participant = $participant;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
try {
$app = app('wechat.official_account');
$wechat_user = $app->user->get($this->participant->official_openid);
if ($wechat_user) {
$nickname = $wechat_user['nickname']??null;
$this->participant->nickname = $nickname;
$this->participant->unionid = $wechat_user['unionid']??null;
$this->participant->subscribe = $wechat_user['subscribe']??0;
$this->participant->sex = $wechat_user['sex']??null;
$this->participant->city = $wechat_user['city']??null;
$this->participant->province = $wechat_user['province']??null;
$this->participant->country = $wechat_user['country']??null;
$this->participant->avatar = $wechat_user['headimgurl']??null;
$this->participant->subscribe_time = $wechat_user['subscribe_time']??null;
$this->participant->save();
$key = Participant::PART_KEY;
$key = $key.$this->participant->official_openid;
//添加一次机会
//更新緩存
Cache::forever($key, $this->participant);
}
} catch (Exception $e) {
}
}
}