/** * 生产微信的token * @return null * @throws \Exception */ public function getWeixinToken($appid = null, $appsecret = null) { $wxClient = new WeixinClient(); $appid = is_null($appid) ? Session::get('wx_appid') : $appid; $appsecret = is_null($appsecret) ? Session::get('wx_appsecret') : $appsecret; $accessToken = $wxClient->applyAccessToken($appid, $appsecret); if ($accessToken == NULL) { throw new \Exception("weixin get token error", 9000); } return $accessToken; }
/** * Execute the console command. * * @return mixed */ public function fire() { $menu = Config::get('weixin.menu.buyer'); $data_string = urldecode(json_encode($menu)); $mq = new MQ(); $access_token = $mq->getWeixinAccessTokenByName('buyer'); $wxClient = new WeixinClient(); $rt = $wxClient->setMenu($data_string, $access_token); if ($rt->errcode == 0) { $this->info('success'); } else { $this->error(sprintf("failed, errcode: %d, errmsg: %s", $rt->errcode, $rt->errmsg)); } return; }
/** * 获得微信jsapi的配置信息 * @return stdClass */ public function getJsapiConfig() { $mq = new MQ(); $jsapiTicket = $mq->getWeixinJsapiTicketByName('buyer'); $url = \Request::fullUrl(); $noncestr = Tool::getRandChar(16); $timestamp = time(); $weixinClient = new WeixinClient(); $signature = $weixinClient->getSignature($jsapiTicket, $url, $noncestr, $timestamp); $config = new \stdClass(); $config->jsapiTicket = $jsapiTicket; $config->url = $url; $config->noncestr = $noncestr; $config->timestamp = $timestamp; $config->signature = $signature; $config->appid = \Config::get('weixin.buyer.appid'); return $config; }
private function _sendTplMsg($data) { $mq = new MQ(); $access_token = $mq->getWeixinAccessTokenByName('seller'); $wxClient = new WeixinClient(); $wxClient->sendTemplateMessage(json_encode($data), $access_token); }
public function getUserInfo(WeixinClient $weixinClient, $openid, $appid, $appsecret) { $accessToken = $this->getWeixinToken($appid, $appsecret); $ret = $weixinClient->getUserInfoByOpenId($openid, $accessToken); return $ret; }