participant = $array['participant']; $this->participant_helper = $array['participant_helper']; $container = new Container(); $this->sms = new Sms($container); } /** * Execute the job. * * @return void */ public function handle() { try { $participant = $this->participant; $participant_helper = $this->participant_helper; $result = $this->textMessage($participant); if (!empty($result['errcode']) && $result['errmsg'] != 'ok') {//发送失败 //Todo模板消息 $result = $this->templateMessage($participant, $participant_helper); if (!empty($result['errcode']) && $result['errmsg'] != 'ok') {//发送失败 #TODO记录 } } } catch (Exception $e) { //TODO通知管理员 $message = $e->getMessage(); $this->sms->sentMessage($mobile, $message); } } public function templateMessage($participant, $participant_helper) { $param = [ 'url'=>env('APP_URL').'/red/packet/activity/wechat/auth', 'share_user_name'=>$participant['nickname'], 'user_name'=>$participant_helper['nickname'], 'chance'=>$participant['chance'], 'openid'=>$participant['official_openid'] ]; $result = \WechatService::shareSuccessNotice($param); return $result; } //客服信息 public function textMessage($participant) { $app = app('wechat.official_account'); // $url = env('APP_URL')."/rp/#/redPacketFruit?official_openid=".$participant['official_openid']; $url = env('APP_URL')."/red/packet/activity/wechat/auth"; $nickname = $participant['nickname']?:'朋友'; $message = $nickname.',恭喜您!获得'.$participant['chance'].'次收集果子机会,马上领取GO! '; $text = new Text($message); $openId = $participant['official_openid']; $result = $app->customer_service->message($text)->to($openId)->send(); return $result; } }