Files
kiri-wchat/wx/Account.php
T
2023-11-14 12:39:28 +08:00

136 lines
3.7 KiB
PHP

<?php
/**
* Created by PhpStorm.
* User: whwyy
* Date: 2018/4/19 0019
* Time: 16:12
*/
namespace wchat\wx;
use Exception;
use wchat\common\Result;
class Account extends SmallProgram
{
/**
* @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';
return $this->get('api.weixin.qq.com', '/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('api.weixin.qq.com', '/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('api.weixin.qq.com', '/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('api.weixin.qq.com', '/sns/userinfo', $query);
}
/**
* @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('api.weixin.qq.com', $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->payConfig->getAccessToken();
if ($auto_color) {
$sendBody['line_color'] = $line_color;
}
return $this->get('api.weixin.qq.com', $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 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->payConfig->getAccessToken();
if ($auto_color) {
$sendBody['line_color'] = $line_color;
}
return $this->get('api.weixin.qq.com', $url . $this->payConfig->getAccessToken(), $sendBody);
}
}