eee
This commit is contained in:
+137
-187
@@ -9,204 +9,154 @@
|
||||
namespace wchat\wx;
|
||||
|
||||
use Exception;
|
||||
use Kiri\Client;
|
||||
use wchat\common\Decode;
|
||||
use wchat\common\HttpClient;
|
||||
use wchat\common\Result;
|
||||
|
||||
class Account extends SmallProgram
|
||||
{
|
||||
|
||||
/**
|
||||
* @param $code
|
||||
* @return Result
|
||||
*/
|
||||
public function login($code): Result
|
||||
{
|
||||
$param['appid'] = $this->config->getAppid();
|
||||
$param['secret'] = $this->config->getAppsecret();
|
||||
$param['js_code'] = $code;
|
||||
$param['grant_type'] = 'authorization_code';
|
||||
/**
|
||||
* @param $code
|
||||
* @return Result
|
||||
*/
|
||||
public function login($code): Result
|
||||
{
|
||||
$param['appid'] = $this->payConfig->appId;
|
||||
$param['secret'] = $this->payConfig->appSecret;
|
||||
$param['js_code'] = $code;
|
||||
$param['grant_type'] = 'authorization_code';
|
||||
|
||||
$client = new Client('api.weixin.qq.com', 443, true);
|
||||
$client->withHeader(['Content-Type' => 'application/json']);
|
||||
if (!empty($this->getConfig()->getProxyHost()) && $this->getConfig()->getProxyPort() > 0) {
|
||||
$client->withProxyHost("192.168.0.57")->withProxyPort(12286);
|
||||
return $this->get('/sns/jscode2session', $param);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $code
|
||||
* @return Result
|
||||
*/
|
||||
public function AppLogin($code): Result
|
||||
{
|
||||
$param['appid'] = $this->payConfig->pay->wx->appId;
|
||||
$param['secret'] = $this->payConfig->pay->wx->appSecret;
|
||||
$param['js_code'] = $code;
|
||||
$param['grant_type'] = 'authorization_code';
|
||||
|
||||
return $this->get('/sns/oauth2/access_token', $param);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $openid
|
||||
* @return Result
|
||||
* @throws Exception
|
||||
*/
|
||||
public function getPublicUserInfo($openid): Result
|
||||
{
|
||||
$query = [
|
||||
'access_token' => $this->payConfig->getAccessToken(),
|
||||
'openid' => $openid,
|
||||
'lang' => 'zh_CN'
|
||||
];
|
||||
return $this->get('/cgi-bin/user/info', $query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $openid
|
||||
* @return Result
|
||||
* @throws Exception
|
||||
*/
|
||||
public function getAppUserInfo($openid): Result
|
||||
{
|
||||
$query = [
|
||||
'access_token' => $this->payConfig->getAccessToken(),
|
||||
'openid' => $openid,
|
||||
];
|
||||
return $this->get('/sns/userinfo', $query);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $encryptedData
|
||||
* @param $iv
|
||||
* @param $sessionKey
|
||||
* @param bool $asArray
|
||||
* @return object|array
|
||||
* @throws
|
||||
*
|
||||
* * <li>-41001: encodingAesKey 非法</li>
|
||||
* <li>-41003: aes 解密失败</li>
|
||||
* <li>-41004: 解密后得到的buffer非法</li>
|
||||
* <li>-41005: base64加密失败</li>
|
||||
* <li>-41016: base64解密失败</li>
|
||||
*/
|
||||
public function decode($encryptedData, $iv, $sessionKey, bool $asArray = false): object|array
|
||||
{
|
||||
$decode = new Decode();
|
||||
$decode->setSessionKey($sessionKey);
|
||||
$decode->setEncryptedData($encryptedData);
|
||||
$decode->setAppId($this->payConfig->getAppid());
|
||||
$decode->setIv($iv);
|
||||
|
||||
return $decode->decode($asArray);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $path
|
||||
* @param $width
|
||||
* @return array|mixed|Result
|
||||
* @throws Exception
|
||||
*/
|
||||
public function createwxaqrcode($path, $width): mixed
|
||||
{
|
||||
$url = 'cgi-bin/wxaapp/createwxaqrcode?access_token=';
|
||||
$sendBody['path'] = $path;
|
||||
$sendBody['width'] = $width;
|
||||
|
||||
return $this->get($url . $this->payConfig->getAccessToken(), $sendBody);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $path
|
||||
* @param $width
|
||||
* @param bool $is_hyaline
|
||||
* @param bool $auto_color
|
||||
* @param string $line_color
|
||||
* @return Result
|
||||
*/
|
||||
public function getwxacode($path, $width, bool $is_hyaline = false, bool $auto_color = false, string $line_color = ''): Result
|
||||
{
|
||||
$sendBody['path'] = $path;
|
||||
$sendBody['width'] = $width;
|
||||
$sendBody['auto_color'] = $auto_color;
|
||||
$sendBody['is_hyaline'] = $is_hyaline;
|
||||
$url = 'wxa/getwxacode?access_token=' . $this->getConfig()->getAccessToken();
|
||||
if ($auto_color) {
|
||||
$sendBody['line_color'] = $line_color;
|
||||
}
|
||||
$client->get('sns/jscode2session', $param);
|
||||
$client->close();
|
||||
return $this->get($url . $this->payConfig->getAccessToken(), $sendBody);
|
||||
|
||||
if (!in_array($client->getStatusCode(), [101, 200, 201])) {
|
||||
return new Result(code: 505, message: $client->getBody());
|
||||
}
|
||||
$body = json_decode($client->getBody(), true);
|
||||
if (isset($body['errcode']) && $body['errcode'] != 0) {
|
||||
return new Result(code: $body['errcode'], message: $body['errmsg']);
|
||||
} else {
|
||||
return new Result(code: 0, data: $body);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $openid
|
||||
* @return Result
|
||||
* @throws Exception
|
||||
*/
|
||||
public function getPublicUserInfo($openid): Result
|
||||
{
|
||||
$query = [
|
||||
'access_token' => $this->config->getAccessToken(),
|
||||
'openid' => $openid,
|
||||
'lang' => 'zh_CN'
|
||||
];
|
||||
|
||||
$client = new Client('api.weixin.qq.com', 443, true);
|
||||
$client->withHeader(['Content-Type' => 'application/json']);
|
||||
if (!empty($this->getConfig()->getProxyHost()) && $this->getConfig()->getProxyPort() > 0) {
|
||||
$client->withProxyHost("192.168.0.57")->withProxyPort(12286);
|
||||
/**
|
||||
* @param $path
|
||||
* @param $width
|
||||
* @param bool $is_hyaline
|
||||
* @param bool $auto_color
|
||||
* @param string $line_color
|
||||
* @return Result
|
||||
*/
|
||||
public function getwxacodeunlimit($path, $width, bool $is_hyaline = false, bool $auto_color = false, string $line_color = ''): Result
|
||||
{
|
||||
$sendBody['path'] = $path;
|
||||
$sendBody['width'] = $width;
|
||||
$sendBody['auto_color'] = $auto_color;
|
||||
$sendBody['is_hyaline'] = $is_hyaline;
|
||||
$url = 'wxa/getwxacodeunlimit?access_token=' . $this->getConfig()->getAccessToken();
|
||||
if ($auto_color) {
|
||||
$sendBody['line_color'] = $line_color;
|
||||
}
|
||||
$client->get('cgi-bin/user/info', $query);
|
||||
$client->close();
|
||||
|
||||
if (!in_array($client->getStatusCode(), [101, 200, 201])) {
|
||||
return new Result(code: 505, message: $client->getBody());
|
||||
}
|
||||
$body = json_decode($client->getBody(), true);
|
||||
if (isset($body['errcode']) && $body['errcode'] != 0) {
|
||||
return new Result(code: $body['errcode'], message: $body['errmsg']);
|
||||
}
|
||||
return new Result(code: 0, data: $body);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $encryptedData
|
||||
* @param $iv
|
||||
* @param $sessionKey
|
||||
* @param bool $asArray
|
||||
* @return object|array
|
||||
* @throws
|
||||
*
|
||||
* * <li>-41001: encodingAesKey 非法</li>
|
||||
* <li>-41003: aes 解密失败</li>
|
||||
* <li>-41004: 解密后得到的buffer非法</li>
|
||||
* <li>-41005: base64加密失败</li>
|
||||
* <li>-41016: base64解密失败</li>
|
||||
*/
|
||||
public function decode($encryptedData, $iv, $sessionKey, bool $asArray = false): object|array
|
||||
{
|
||||
$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): mixed
|
||||
{
|
||||
$url = 'cgi-bin/wxaapp/createwxaqrcode?access_token=';
|
||||
$sendBody['path'] = $path;
|
||||
$sendBody['width'] = $width;
|
||||
$client = new Client('api.weixin.qq.com', 443, true);
|
||||
$client->withHeader(['Content-Type' => 'application/json']);
|
||||
|
||||
$proxyHost = $this->getConfig()->getProxyHost();
|
||||
$proxyPort = $this->getConfig()->getProxyPort();
|
||||
if (!empty($proxyHost) && $proxyPort > 0) {
|
||||
$client->withProxyHost($proxyHost)->withProxyPort($proxyPort);
|
||||
}
|
||||
$client->post($url . $this->getConfig()->getAccessToken(), $sendBody);
|
||||
$client->close();
|
||||
if (!in_array($client->getStatusCode(), [101, 200, 201])) {
|
||||
return new Result(code: 505, message: $client->getBody());
|
||||
}
|
||||
$body = json_decode($client->getBody(), true);
|
||||
if (!is_null($body)) {
|
||||
return new Result(code: $body['errcode'], message: $body['errmsg']);
|
||||
} else {
|
||||
return new Result(code: 0, data: $client->getBody());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $path
|
||||
* @param $width
|
||||
* @param bool $is_hyaline
|
||||
* @param bool $auto_color
|
||||
* @param string $line_color
|
||||
* @return Result
|
||||
*/
|
||||
public function getwxacode($path, $width, bool $is_hyaline = false, bool $auto_color = false, string $line_color = ''): Result
|
||||
{
|
||||
$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 = 'wxa/getwxacode?access_token=' . $this->getConfig()->getAccessToken();
|
||||
|
||||
$client = new Client('api.weixin.qq.com', 443, true);
|
||||
$client->withHeader(['Content-Type' => 'application/json']);
|
||||
$client->post($url . $this->getConfig()->getAccessToken(), $sendBody);
|
||||
$client->close();
|
||||
if (!in_array($client->getStatusCode(), [101, 200, 201])) {
|
||||
return new Result(code: 505, message: $client->getBody());
|
||||
}
|
||||
$body = json_decode($client->getBody(), true);
|
||||
if (!is_null($body)) {
|
||||
return new Result(code: $body['errcode'], message: $body['errmsg']);
|
||||
} else {
|
||||
return new Result(code: 0, data: $client->getBody());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $path
|
||||
* @param $width
|
||||
* @param bool $is_hyaline
|
||||
* @param bool $auto_color
|
||||
* @param string $line_color
|
||||
* @return Result
|
||||
*/
|
||||
public function getwxacodeunlimit($path, $width, bool $is_hyaline = false, bool $auto_color = false, string $line_color = ''): Result
|
||||
{
|
||||
$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 = 'wxa/getwxacodeunlimit?access_token=' . $this->getConfig()->getAccessToken();
|
||||
|
||||
$client = new Client('api.weixin.qq.com', 443, true);
|
||||
$client->withHeader(['Content-Type' => 'application/json']);
|
||||
$client->post($url . $this->getConfig()->getAccessToken(), $sendBody);
|
||||
$client->close();
|
||||
if (!in_array($client->getStatusCode(), [101, 200, 201])) {
|
||||
return new Result(code: 505, message: $client->getBody());
|
||||
}
|
||||
$body = json_decode($client->getBody(), true);
|
||||
if (!is_null($body)) {
|
||||
return new Result(code: $body['errcode'], message: $body['errmsg']);
|
||||
} else {
|
||||
return new Result(code: 0, data: $client->getBody());
|
||||
}
|
||||
}
|
||||
return $this->get($url . $this->payConfig->getAccessToken(), $sendBody);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user