public function index() { $wechat = new Wechat($this->options); $wechat->valid(); //明文或兼容模式可以在接口验证通过后注释此句,但加密模式一定不能注释,否则会验证失败 $type = $wechat->getRev()->getRevType(); switch ($type) { case Wechat::MSGTYPE_TEXT: $domain = C('WX_DOMAIN'); $url = $domain . "index.php?m=home&c=Login&a=wechatCallback"; $redirect = $wechat->getOauthRedirect($url); $wechat->text("<a href=\"{$redirect}\">点击登陆</a>")->reply(); exit; break; case Wechat::MSGTYPE_LOCATION: $localtion = $wechat->getRevGeo(); $wechat->text(json_encode($localtion))->reply(); exit; break; case Wechat::EVENT_SUBSCRIBE: $wechat->text("谢谢关注")->reply(); exit; break; case Wechat::MSGTYPE_IMAGE: $wechat->text("...")->reply(); break; default: $wechat->text("Hello World")->reply(); } }
/** * 微信登陆DEMO * @return [type] [description] */ public function getCode() { $data = array(); $wechat = new Wechat($this->options); $wxdata = $wechat->getOauthAccessToken(); dd($wxdata); }