mirror of
https://gitee.com/zoujingli/WeChatDeveloper.git
synced 2025-08-30 02:30:05 +08:00
修改小程序二维码
This commit is contained in:
parent
42933f79b2
commit
7f0a4ed890
@ -20,7 +20,7 @@ use WeChat\Contracts\BasicWeChat;
|
|||||||
use WeChat\Contracts\Tools;
|
use WeChat\Contracts\Tools;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 微信小程序二维码管理
|
* 微信小程序二维码
|
||||||
* Class Qrcode
|
* Class Qrcode
|
||||||
* @package WeMini
|
* @package WeMini
|
||||||
*/
|
*/
|
||||||
@ -32,28 +32,20 @@ class Qrcode extends BasicWeChat
|
|||||||
* 接口A: 适用于需要的码数量较少的业务场景
|
* 接口A: 适用于需要的码数量较少的业务场景
|
||||||
* @param string $path 不能为空,最大长度 128 字节
|
* @param string $path 不能为空,最大长度 128 字节
|
||||||
* @param integer $width 二维码的宽度
|
* @param integer $width 二维码的宽度
|
||||||
* @param bool $auto_color 自动配置线条颜色,如果颜色依然是黑色,则说明不建议配置主色调
|
* @param bool $autoColor 自动配置线条颜色,如果颜色依然是黑色,则说明不建议配置主色调
|
||||||
* @param array $line_color auto_color 为 false 时生效
|
* @param array $lineColor auto_color 为 false 时生效
|
||||||
* @param boolean $is_hyaline 是否需要透明底色
|
* @param boolean $isHyaline 透明底色
|
||||||
* @param null|string $outType 输出类型
|
* @param string|null $outType 输出类型
|
||||||
* @return array|string
|
* @return string|array
|
||||||
* @throws \WeChat\Exceptions\InvalidResponseException
|
* @throws \WeChat\Exceptions\InvalidResponseException
|
||||||
* @throws \WeChat\Exceptions\LocalCacheException
|
* @throws \WeChat\Exceptions\LocalCacheException
|
||||||
*/
|
*/
|
||||||
public function createMiniPath($path, $width = 430, $auto_color = false, $line_color = ["r" => "0", "g" => "0", "b" => "0"], $is_hyaline = true, $outType = null)
|
public function createMiniPath($path, $width = 430, $autoColor = false, $lineColor = ["r" => "0", "g" => "0", "b" => "0"], $isHyaline = true, $outType = null)
|
||||||
{
|
{
|
||||||
$url = 'https://api.weixin.qq.com/wxa/getwxacode?access_token=ACCESS_TOKEN';
|
$url = 'https://api.weixin.qq.com/wxa/getwxacode?access_token=ACCESS_TOKEN';
|
||||||
$this->registerApi($url, __FUNCTION__, func_get_args());
|
$this->registerApi($url, __FUNCTION__, func_get_args());
|
||||||
$data = ['path' => $path, 'width' => $width, 'auto_color' => $auto_color, 'line_color' => $line_color, 'is_hyaline' => $is_hyaline];
|
$data = ['path' => $path, 'width' => $width, 'auto_color' => $autoColor, 'line_color' => $lineColor, 'is_hyaline' => $isHyaline];
|
||||||
$result = Tools::post($url, Tools::arr2json($data));
|
return $this->parseResult(Tools::post($url, Tools::arr2json($data)), $outType);
|
||||||
if (is_array($json = json_decode($result, true))) {
|
|
||||||
if (!$this->isTry && isset($json['errcode']) && in_array($json['errcode'], ['40014', '40001', '41001', '42001'])) {
|
|
||||||
[$this->delAccessToken(), $this->isTry = true];
|
|
||||||
return call_user_func_array([$this, $this->currentMethod['method']], $this->currentMethod['arguments']);
|
|
||||||
}
|
|
||||||
return Tools::json2arr($result);
|
|
||||||
}
|
|
||||||
return is_null($outType) ? $result : $outType($result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -62,29 +54,22 @@ class Qrcode extends BasicWeChat
|
|||||||
* @param string $scene 最大32个可见字符,只支持数字
|
* @param string $scene 最大32个可见字符,只支持数字
|
||||||
* @param string $page 必须是已经发布的小程序存在的页面
|
* @param string $page 必须是已经发布的小程序存在的页面
|
||||||
* @param integer $width 二维码的宽度
|
* @param integer $width 二维码的宽度
|
||||||
* @param bool $auto_color 自动配置线条颜色,如果颜色依然是黑色,则说明不建议配置主色调
|
* @param bool $autoColor 自动配置线条颜色,如果颜色依然是黑色,则说明不建议配置主色调
|
||||||
* @param array $line_color auto_color 为 false 时生效
|
* @param array $lineColor auto_color 为 false 时生效
|
||||||
* @param boolean $is_hyaline 是否需要透明底色
|
* @param bool $isHyaline 是否需要透明底色
|
||||||
* @param null|string $outType 输出类型
|
* @param null|string $outType 输出类型
|
||||||
* @param array $extra 其他参数
|
* @param array $extra 其他参数
|
||||||
* @return array|string
|
* @return array|string
|
||||||
* @throws \WeChat\Exceptions\InvalidResponseException
|
* @throws \WeChat\Exceptions\InvalidResponseException
|
||||||
* @throws \WeChat\Exceptions\LocalCacheException
|
* @throws \WeChat\Exceptions\LocalCacheException
|
||||||
*/
|
*/
|
||||||
public function createMiniScene($scene, $page, $width = 430, $auto_color = false, $line_color = ["r" => "0", "g" => "0", "b" => "0"], $is_hyaline = true, $outType = null, array $extra = [])
|
public function createMiniScene($scene, $page = '', $width = 430, $autoColor = false, $lineColor = ["r" => "0", "g" => "0", "b" => "0"], $isHyaline = true, $outType = null, array $extra = [])
|
||||||
{
|
{
|
||||||
$url = 'https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=ACCESS_TOKEN';
|
$url = 'https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=ACCESS_TOKEN';
|
||||||
$data = array_merge(['scene' => $scene, 'width' => $width, 'auto_color' => $auto_color, 'page' => $page, 'line_color' => $line_color, 'is_hyaline' => $is_hyaline], $extra);
|
|
||||||
$this->registerApi($url, __FUNCTION__, func_get_args());
|
$this->registerApi($url, __FUNCTION__, func_get_args());
|
||||||
$result = Tools::post($url, Tools::arr2json($data));
|
$data = ['scene' => $scene, 'width' => $width, 'page' => $page, 'auto_color' => $autoColor, 'line_color' => $lineColor, 'is_hyaline' => $isHyaline, 'check_path' => false];
|
||||||
if (is_array($json = json_decode($result, true))) {
|
if (empty($page)) unset($data['page']);
|
||||||
if (!$this->isTry && isset($json['errcode']) && in_array($json['errcode'], ['40014', '40001', '41001', '42001'])) {
|
return $this->parseResult(Tools::post($url, Tools::arr2json(array_merge($data, $extra))), $outType);
|
||||||
[$this->delAccessToken(), $this->isTry = true];
|
|
||||||
return call_user_func_array([$this, $this->currentMethod['method']], $this->currentMethod['arguments']);
|
|
||||||
}
|
|
||||||
return Tools::json2arr($result);
|
|
||||||
}
|
|
||||||
return is_null($outType) ? $result : $outType($result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -92,7 +77,7 @@ class Qrcode extends BasicWeChat
|
|||||||
* 接口C:适用于需要的码数量较少的业务场景
|
* 接口C:适用于需要的码数量较少的业务场景
|
||||||
* @param string $path 不能为空,最大长度 128 字节
|
* @param string $path 不能为空,最大长度 128 字节
|
||||||
* @param integer $width 二维码的宽度
|
* @param integer $width 二维码的宽度
|
||||||
* @param null|string $outType 输出类型
|
* @param string|null $outType 输出类型
|
||||||
* @return array|string
|
* @return array|string
|
||||||
* @throws \WeChat\Exceptions\InvalidResponseException
|
* @throws \WeChat\Exceptions\InvalidResponseException
|
||||||
* @throws \WeChat\Exceptions\LocalCacheException
|
* @throws \WeChat\Exceptions\LocalCacheException
|
||||||
@ -101,14 +86,26 @@ class Qrcode extends BasicWeChat
|
|||||||
{
|
{
|
||||||
$url = 'https://api.weixin.qq.com/cgi-bin/wxaapp/createwxaqrcode?access_token=ACCESS_TOKEN';
|
$url = 'https://api.weixin.qq.com/cgi-bin/wxaapp/createwxaqrcode?access_token=ACCESS_TOKEN';
|
||||||
$this->registerApi($url, __FUNCTION__, func_get_args());
|
$this->registerApi($url, __FUNCTION__, func_get_args());
|
||||||
$result = Tools::post($url, Tools::arr2json(['path' => $path, 'width' => $width]));
|
return $this->parseResult(Tools::post($url, Tools::arr2json(['path' => $path, 'width' => $width])), $outType);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 解释接口数据
|
||||||
|
* @param bool|string $result
|
||||||
|
* @param null|string $outType
|
||||||
|
* @return array|mixed
|
||||||
|
* @throws \WeChat\Exceptions\InvalidResponseException
|
||||||
|
*/
|
||||||
|
private function parseResult($result, $outType)
|
||||||
|
{
|
||||||
if (is_array($json = json_decode($result, true))) {
|
if (is_array($json = json_decode($result, true))) {
|
||||||
if (!$this->isTry && isset($json['errcode']) && in_array($json['errcode'], ['40014', '40001', '41001', '42001'])) {
|
if (!$this->isTry && isset($json['errcode']) && in_array($json['errcode'], ['40014', '40001', '41001', '42001'])) {
|
||||||
[$this->delAccessToken(), $this->isTry = true];
|
[$this->delAccessToken(), $this->isTry = true];
|
||||||
return call_user_func_array([$this, $this->currentMethod['method']], $this->currentMethod['arguments']);
|
return call_user_func_array([$this, $this->currentMethod['method']], $this->currentMethod['arguments']);
|
||||||
}
|
}
|
||||||
return Tools::json2arr($result);
|
return Tools::json2arr($result);
|
||||||
}
|
} else {
|
||||||
return is_null($outType) ? $result : $outType($result);
|
return is_null($outType) ? $result : $outType($result);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user