DiverseYouthNightSchool/application/api/controller/WechatUtil.php

195 lines
11 KiB
PHP
Raw Normal View History

<?php
namespace app\api\controller;
use addons\epay\library\Service;
use app\common\controller\Api;
use app\common\model\style\HomeImages;
/**
* 微信工具类接口
*/
class WechatUtil extends Api
{
protected $noNeedLogin = ['scheme','link',"codeunlimit"];
protected $noNeedRight = ['*'];
public function index()
{
$this->success('请求成功');
}
/**
* @ApiTitle(微信小程序生成url-scheme)
* @ApiSummary(微信小程序生成url-scheme)
* @ApiRoute(/api/wechat_util/scheme)
* @ApiMethod(POST)
* @ApiParams (name="path", type="string", required=false, description="通过 scheme 码进入的小程序页面路径,必须是已经发布的小程序存在的页面,不可携带 query。path 为空时会跳转小程序主页。")
* @ApiParams (name="query", type="string", required=false, description="通过 scheme 码进入小程序时的 query最大1024个字符只支持数字大小写英文以及部分特殊字符")
* @ApiParams (name="env_version", type="string",required=false , description="默认值release。要打开的小程序版本。正式版为release体验版为trial开发版为develop仅在微信外打开时生效。")
* @ApiParams (name="expire_time", type="number",required=false , description="到期失效的 scheme 码的失效时间,为 Unix 时间戳。生成的到期失效 scheme 码在该时间前有效。最长有效期为30天。is_expire 为 true 且 expire_type 为 0 时必填")
* @ApiParams (name="expire_type", type="number",required=false , description="默认值0到期失效的 scheme 码失效类型失效时间0失效间隔天数1")
* @ApiParams (name="expire_interval", type="number",required=false , description="到期失效的 scheme 码的失效间隔天数。生成的到期失效 scheme 码在该间隔时间到达前有效。最长间隔天数为30天。is_expire 为 true 且 expire_type 为 1 时必填")
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="openlink", type="string", required=true, sample="生成的小程序 scheme 码")
* @ApiReturn({
"code" => 1,
"msg" => "获取成功",
"data" => {}
*})
*/
public function scheme() {
$q_params = [];
$path = $this->request->post('path/s','');
$query = $this->request->post('query/s','');
$env_version = $this->request->post('env_version/s','release');
$expire_time = $this->request->post('expire_time/d',0);
$expire_type = $this->request->post('expire_type/d',0);
$expire_interval = $this->request->post('expire_interval/d',0);
$jump_wxa = compact('env_version');
if($path)$jump_wxa["path"] = $path;
if($query)$jump_wxa["query"] = $query;
if($expire_time)$q_params["expire_time"] = $expire_time;
if($expire_interval)$q_params["expire_interval"] = $expire_interval;
$q_params["expire_type"] = $expire_type;
$q_params["jump_wxa"] = $jump_wxa;
try {
// 实例对应的接口对象
$scheme = new \WeMini\Scheme(Service::wechatConfig());
$res= $scheme->create($q_params);
} catch (\Exception $e){
// Log::log($e->getMessage());
$this->error($e->getMessage(),['errcode'=>$e->getCode()]);
}
$this->success('生成成功', $res);
}
/**
* @ApiTitle(微信小程序生成url-link)
* @ApiSummary(微信小程序生成url-link)
* @ApiRoute(/api/wechat_util/link)
* @ApiMethod(POST)
* @ApiParams (name="path", type="string", required=false, description="通过 URL Link 进入的小程序页面路径,必须是已经发布的小程序存在的页面,不可携带 query 。path 为空时会跳转小程序主页")
* @ApiParams (name="query", type="string", required=false, description="通过 scheme 码进入小程序时的 query最大1024个字符只支持数字大小写英文以及部分特殊字符")
* @ApiParams (name="env_version", type="string",required=false , description="默认值release。要打开的小程序版本。正式版为release体验版为trial开发版为develop仅在微信外打开时生效。")
* @ApiParams (name="expire_time", type="number",required=false , description="到期失效的 scheme 码的失效时间,为 Unix 时间戳。生成的到期失效 scheme 码在该时间前有效。最长有效期为30天。is_expire 为 true 且 expire_type 为 0 时必填")
* @ApiParams (name="expire_type", type="number",required=false , description="默认值0到期失效的 scheme 码失效类型失效时间0失效间隔天数1")
* @ApiParams (name="cloud_env", type="string",required=false , description="云开发静态网站自定义 H5 配置参数: 云开发环境")
* @ApiParams (name="cloud_domain", type="string",required=false , description="云开发静态网站自定义 H5 配置参数: 静态网站自定义域名,不填则使用默认域名")
* @ApiParams (name="cloud_path", type="string",required=false , description="云开发静态网站自定义 H5 配置参数: 云开发静态网站 H5 页面路径,不可携带 query")
* @ApiParams (name="cloud_query", type="string",required=false , description="云开发静态网站自定义 H5 配置参数: 云开发静态网站 H5 页面 query 参数,最大 1024 个字符,只支持数字,大小写英文以及部分特殊字符")
* @ApiParams (name="cloud_resource_appid", type="string",required=false , description="云开发静态网站自定义 H5 配置参数: 第三方批量代云开发时必填,表示创建该 env 的 appid (小程序/第三方平台)")
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="url_link", type="string", required=true, sample="生成的小程序 URL Link")
* @ApiReturn({
"code" => 1,
"msg" => "获取成功",
"data" => {}
*})
*/
public function link() {
$q_params = [];
$path = $this->request->post('path/s','');
$query = $this->request->post('query/s','');
$env_version = $this->request->post('env_version/s','release');
$expire_time = $this->request->post('expire_time/d',0);
$expire_type = $this->request->post('expire_type/d',0);
$expire_interval = $this->request->post('expire_interval/d',0);
$cloud_env = $this->request->post('cloud_env/s',0);
$cloud_domain = $this->request->post('cloud_domain/s',0);
$cloud_path = $this->request->post('cloud_path/s',0);
$cloud_query = $this->request->post('cloud_query/s',0);
$cloud_resource_appid = $this->request->post('cloud_resource_appid/s',0);
$cloud_base = [];
if($cloud_env)$cloud_base["env"] = $cloud_env;
if($cloud_domain)$cloud_base["domain"] = $cloud_domain;
if($cloud_path)$cloud_base["path"] = $cloud_path;
if($cloud_query)$cloud_base["cloud_query"] = $cloud_query;
if($cloud_resource_appid)$cloud_base["resource_appid"] = $cloud_resource_appid;
if($path)$q_params["path"] = $path;
if($query)$q_params["query"] = $query;
if($env_version)$q_params["env_version"] = $env_version;
if($expire_time)$q_params["expire_time"] = $expire_time;
if($expire_interval)$q_params["expire_interval"] = $expire_interval;
if($expire_type)$q_params["expire_type"] = $expire_type;
if($cloud_base)$q_params["cloud_base"] = $cloud_base;
try {
// 实例对应的接口对象
$scheme = new \WeMini\Scheme(Service::wechatConfig());
$res= $scheme->urlLink($q_params);
} catch (\Exception $e){
// Log::log($e->getMessage());
$this->error($e->getMessage(),['errcode'=>$e->getCode()]);
}
$this->success('生成成功', $res);
}
/**
* @ApiTitle(获取不限制的小程序码(太阳码))
* @ApiSummary(获取不限制的小程序码(太阳码))
* @ApiRoute(/api/wechat_util/codeunlimit)
* @ApiMethod(POST)
* @ApiParams (name="page", type="string", required=false, description="默认是主页,页面 page例如 pages/index/index根路径前不要填加 /不能携带参数参数请放在scene字段里如果不填写这个字段默认跳主页面。scancode_time为系统保留参数不允许配置")
* @ApiParams (name="scene", type="string", required=false, description="最大32个可见字符只支持数字大小写英文以及部分特殊字符!#$&'()*+,/:;=?@-._~,其它字符请自行编码为合法字符(因不支持%,中文无法使用 urlencode 处理,请使用其他编码方式)")
* @ApiParams (name="env_version", type="string",required=false , description="默认值release。要打开的小程序版本。正式版为release体验版为trial开发版为develop仅在微信外打开时生效。")
* @ApiParams (name="check_path", type="bool",required=false , description="默认是true检查page 是否存在,为 true 时 page 必须是已经发布的小程序存在的页面(否则报错);为 false 时允许小程序未发布或者 page 不存在, 但page 有数量上限60000个请勿滥用。")
* @ApiParams (name="width", type="number",required=false , description="默认430二维码的宽度单位 px最小 280px最大 1280px")
* @ApiParams (name="auto_color", type="bool",required=false , description="自动配置线条颜色,如果颜色依然是黑色,则说明不建议配置主色调,默认 false")
* @ApiParams (name="line_color", type="json",required=false , description="默认是{r:0,g:0,b:0} 。auto_color 为 false 时生效,使用 rgb 设置颜色 例如 {r:xxx,g:xxx,b:xxx} 十进制表示")
* @ApiParams (name="is_hyaline", type="bool",required=false , description="默认是false是否需要透明底色为 true 时,生成透明底色的小程序")
* @ApiReturn({
"code" => 1,
"msg" => "获取成功",
"data" => {}
*})
*/
public function codeunlimit() {
$page = $this->request->post('page/s','');
$scene = $this->request->post('scene/s','');
$env_version = $this->request->post('env_version/s','release');
$check_path = $this->request->post('check_path/d',1);
$width = $this->request->post('width/d',430);
$auto_color = $this->request->post('auto_color/d',0);
$line_color = $this->request->post('line_color/s',0);
$is_hyaline = $this->request->post('is_hyaline/d',1);
try {
// 实例对应的接口对象
$res = \bw\Common::getMiniappCode($scene, $page, $width, $auto_color ? true : false, $line_color, $is_hyaline ? true : false, null, $check_path ? true : false, $env_version,false);
} catch (\Exception $e){
// Log::log($e->getMessage());
$this->error($e->getMessage(),['errcode'=>$e->getCode()]);
}
$this->success('生成成功', $res);
}
}