Files

132 lines
3.8 KiB
PHP
Raw Permalink Normal View History

2018-07-19 12:10:22 +08:00
<?php
/**
* Created by PhpStorm.
* User: whwyy
* Date: 2018/4/19 0019
* Time: 16:12
*/
2019-07-12 19:25:47 +08:00
2020-03-05 12:41:49 +08:00
namespace wchat\wx;
2019-11-11 18:14:47 +08:00
2020-03-05 12:41:49 +08:00
use wchat\common\Result;
2019-11-11 18:14:47 +08:00
class Account extends SmallProgram
2018-07-19 12:10:22 +08:00
{
2019-07-12 19:25:47 +08:00
2023-11-14 00:45:54 +08:00
/**
2023-11-14 14:10:36 +08:00
* @param string $code
2023-11-14 00:45:54 +08:00
* @return Result
*/
2023-11-14 14:10:36 +08:00
public function login(string $code): Result
2023-11-14 00:45:54 +08:00
{
$param['appid'] = $this->payConfig->appId;
$param['secret'] = $this->payConfig->appSecret;
$param['js_code'] = $code;
$param['grant_type'] = 'authorization_code';
2023-11-14 12:39:28 +08:00
return $this->get('api.weixin.qq.com', '/sns/jscode2session', $param);
2023-11-14 00:45:54 +08:00
}
/**
2023-11-14 14:10:36 +08:00
* @param string $code
2023-11-14 00:45:54 +08:00
* @return Result
*/
2023-11-14 14:10:36 +08:00
public function AppLogin(string $code): Result
2023-11-14 00:45:54 +08:00
{
$param['appid'] = $this->payConfig->pay->wx->appId;
$param['secret'] = $this->payConfig->pay->wx->appSecret;
$param['js_code'] = $code;
$param['grant_type'] = 'authorization_code';
2023-11-14 12:39:28 +08:00
return $this->get('api.weixin.qq.com', '/sns/oauth2/access_token', $param);
2023-11-14 00:45:54 +08:00
}
/**
2023-11-14 14:10:36 +08:00
* @param string $openid
2023-11-14 00:45:54 +08:00
* @return Result
*/
2023-11-14 14:10:36 +08:00
public function getPublicUserInfo(string $openid): Result
2023-11-14 00:45:54 +08:00
{
$query = [
'access_token' => $this->payConfig->getAccessToken(),
'openid' => $openid,
'lang' => 'zh_CN'
];
2023-11-14 12:39:28 +08:00
return $this->get('api.weixin.qq.com', '/cgi-bin/user/info', $query);
2023-11-14 00:45:54 +08:00
}
/**
2023-11-14 14:10:36 +08:00
* @param string $openid
2023-11-14 00:45:54 +08:00
* @return Result
*/
2023-11-14 14:10:36 +08:00
public function getAppUserInfo(string $openid): Result
2023-11-14 00:45:54 +08:00
{
$query = [
'access_token' => $this->payConfig->getAccessToken(),
'openid' => $openid,
];
2023-11-14 12:39:28 +08:00
return $this->get('api.weixin.qq.com', '/sns/userinfo', $query);
2023-11-14 00:45:54 +08:00
}
/**
2023-11-14 14:10:36 +08:00
* @param string $path
* @param int $width
2023-11-14 00:45:54 +08:00
* @return array|mixed|Result
*/
2023-11-14 14:10:36 +08:00
public function createwxaqrcode(string $path, int $width): mixed
2023-11-14 00:45:54 +08:00
{
$url = 'cgi-bin/wxaapp/createwxaqrcode?access_token=';
$sendBody['path'] = $path;
$sendBody['width'] = $width;
2023-11-14 12:39:28 +08:00
return $this->get('api.weixin.qq.com', $url . $this->payConfig->getAccessToken(), $sendBody);
2023-11-14 00:45:54 +08:00
}
/**
2023-11-14 14:10:36 +08:00
* @param string $path
* @param int $width
2023-11-14 00:45:54 +08:00
* @param bool $is_hyaline
* @param bool $auto_color
* @param string $line_color
* @return Result
*/
2023-11-14 14:10:36 +08:00
public function getwxacode(string $path, int $width, bool $is_hyaline = false, bool $auto_color = false, string $line_color = ''): Result
2023-11-14 00:45:54 +08:00
{
$sendBody['path'] = $path;
$sendBody['width'] = $width;
$sendBody['auto_color'] = $auto_color;
$sendBody['is_hyaline'] = $is_hyaline;
2023-11-14 12:39:28 +08:00
$url = 'wxa/getwxacode?access_token=' . $this->payConfig->getAccessToken();
2023-11-14 00:45:54 +08:00
if ($auto_color) {
$sendBody['line_color'] = $line_color;
2023-11-07 15:13:11 +08:00
}
2023-11-14 12:39:28 +08:00
return $this->get('api.weixin.qq.com', $url . $this->payConfig->getAccessToken(), $sendBody);
2023-11-14 00:45:54 +08:00
}
/**
2023-11-14 14:10:36 +08:00
* @param string $path
* @param int $width
2023-11-14 00:45:54 +08:00
* @param bool $is_hyaline
* @param bool $auto_color
* @param string $line_color
* @return Result
*/
2023-11-14 14:10:36 +08:00
public function getwxacodeunlimit(string $path, int $width, bool $is_hyaline = false, bool $auto_color = false, string $line_color = ''): Result
2023-11-14 00:45:54 +08:00
{
$sendBody['path'] = $path;
$sendBody['width'] = $width;
$sendBody['auto_color'] = $auto_color;
$sendBody['is_hyaline'] = $is_hyaline;
2023-11-14 12:39:28 +08:00
$url = 'wxa/getwxacodeunlimit?access_token=' . $this->payConfig->getAccessToken();
2023-11-14 00:45:54 +08:00
if ($auto_color) {
$sendBody['line_color'] = $line_color;
2023-11-07 15:13:11 +08:00
}
2023-11-14 12:39:28 +08:00
return $this->get('api.weixin.qq.com', $url . $this->payConfig->getAccessToken(), $sendBody);
2023-11-14 00:45:54 +08:00
}
2022-09-09 16:42:55 +08:00
2019-07-12 18:51:12 +08:00
}