savePath = $path; } /** * @param $code * @return Result */ public function login($code) { $param['appid'] = $this->config->getAppid(); $param['secret'] = $this->config->getAppsecret(); $param['js_code'] = $code; $param['grant_type'] = 'authorization_code'; $this->request->setMethod(HttpClient::GET); $this->request->addHeader('Content-Type', 'application/json'); $this->request->setHost('api.weixin.qq.com'); $this->request->addHeader('Host', 'api.weixin.qq.com'); $this->request->setErrorField('errcode'); $this->request->setErrorMsgField('errmsg'); return $this->request->get('sns/jscode2session', $param); } /** * @param $openid * @return array|mixed|Result * @throws \Exception */ public function getPublicUserInfo($openid) { $query = [ 'access_token' => $this->getAccessToken(), 'openid' => $openid, 'lang' => 'zh_CN' ]; $client = HttpClient::NewRequest(); $client->setAgent($this->config->getAgent()); $client->setUseSwoole($this->config->isUsrSwoole()); $client->setMethod(HttpClient::GET); $client->setIsSSL(true); $client->setHost('api.weixin.qq.com'); $client->addHeader('Host', 'api.weixin.qq.com'); $client->setErrorField('errcode'); $client->setErrorMsgField('errmsg'); return $client->get('user/info', $query); } /** * @param $encryptedData * @param $iv * @param $sessionKey * @param $asArray * @return object|array * @throws * * *
  • -41001: encodingAesKey 非法
  • *
  • -41003: aes 解密失败
  • *
  • -41004: 解密后得到的buffer非法
  • *
  • -41005: base64加密失败
  • *
  • -41016: base64解密失败
  • */ public function decode($encryptedData, $iv, $sessionKey, $asArray = false) { $decode = new Decode(); $decode->setSessionKey($sessionKey); $decode->setEncryptedData($encryptedData); $decode->setAppId($this->config->getAppid()); $decode->setIv($iv); return $decode->decode($asArray); } /** * @param $path * @param $width * @return array|mixed|Result * @throws \Exception */ public function createwxaqrcode($path, $width) { $url = $this->wxaqr . $this->getAccessToken(); $sendBody['path'] = $path; $sendBody['width'] = $width; $this->request->setMethod(HttpClient::POST); $this->request->setCallback([$this, 'saveByPath']); $this->request->setErrorField('errcode'); $this->request->setErrorMsgField('errmsg'); return $this->request->post($url, $sendBody); } /** * @param $path * @param $width * @param bool $is_hyaline * @param bool $auto_color * @param string $line_color * @return array|mixed|Result * @throws \Exception */ public function getwxacode($path, $width, $is_hyaline = false, $auto_color = false, $line_color = '') { $sendBody['path'] = $path; $sendBody['width'] = $width; $sendBody['auto_color'] = $auto_color; $sendBody['is_hyaline'] = $is_hyaline; if ($auto_color) { $sendBody['line_color'] = $line_color; } $url = $this->getwxacode . $this->getAccessToken(); $this->request->setMethod(HttpClient::POST); $this->request->setCallback([$this, 'saveByPath']); $this->request->setErrorField('errcode'); $this->request->setErrorMsgField('errmsg'); return $this->request->post($url, $sendBody); } /** * @param $path * @param $width * @param bool $is_hyaline * @param bool $auto_color * @param string $line_color * @return array|mixed|Result * @throws \Exception */ public function getwxacodeunlimit($path, $width, $is_hyaline = false, $auto_color = false, $line_color = '') { $sendBody['path'] = $path; $sendBody['width'] = $width; $sendBody['auto_color'] = $auto_color; $sendBody['is_hyaline'] = $is_hyaline; if ($auto_color) { $sendBody['line_color'] = $line_color; } $url = $this->getwxacodeunlimit . $this->getAccessToken(); $this->request->setMethod(HttpClient::POST); $this->request->setCallback([$this, 'saveByPath']); $this->request->setErrorField('errcode'); $this->request->setErrorMsgField('errmsg'); return $this->request->post($url, $sendBody); } /** * @param mixed $body * @return string * @throws \Exception */ public function saveByPath($body) { if (!is_null($json = json_decode($body))) { throw new \Exception($json['errmsg'], $json['errcode']); } $push = md5_file($body) . '.png'; file_put_contents($this->savePath . $push, $this->savePath); return $this->savePath . $push; } }