193 lines
5.0 KiB
PHP
193 lines
5.0 KiB
PHP
<?php
|
|
|
|
namespace app\admin\controller\channel;
|
|
|
|
use app\common\controller\Backend;
|
|
use ZipArchive;
|
|
/**
|
|
* 上传代码
|
|
*/
|
|
class Upload extends Backend
|
|
{
|
|
|
|
public function _initialize()
|
|
{
|
|
parent::_initialize();
|
|
}
|
|
|
|
|
|
/**
|
|
* 获取版本
|
|
* @return void
|
|
*/
|
|
public function getVersion(){
|
|
$this->success("获取成功",\think\Config::get('license'));
|
|
}
|
|
|
|
|
|
/**
|
|
* 提交版本
|
|
* @return void
|
|
*/
|
|
public function wechat(){
|
|
|
|
$version = input('version','1.0.0');
|
|
$desc = input('desc','');
|
|
$type = input('type','submit');
|
|
|
|
if(!$version){
|
|
$this->error("请完善版本号");
|
|
}
|
|
|
|
if(!$desc){
|
|
$this->error("请完善版本描述");
|
|
}
|
|
|
|
if(\app\common\library\Platform::getSystemType() == 'single'){
|
|
$domain = $this->request->domain() . '/';
|
|
}else{
|
|
$domain = $this->request->domain() . '/app/index.php';
|
|
}
|
|
|
|
$wxMiniProgramConfig = \app\common\model\config\System::getConfig('wxMiniProgram');
|
|
|
|
$appid = $wxMiniProgramConfig['app_id'];
|
|
$upload_key = $wxMiniProgramConfig['upload_key'];
|
|
|
|
if(!$appid || !$upload_key){
|
|
$this->error("请完善小程序配置信息");
|
|
}
|
|
set_time_limit(0);
|
|
|
|
try {
|
|
$client = \app\common\library\Client::getClient();
|
|
|
|
$response = $client->request("POST",'api/license/upload/wechat',[
|
|
'form_params'=>[
|
|
'version'=>$version,
|
|
'desc'=>$desc,
|
|
'key'=>$upload_key,
|
|
'appid'=>$appid,
|
|
'domain'=>$domain,
|
|
'uniacid'=>UNIACID,
|
|
'actiontype'=>$type
|
|
]
|
|
]);
|
|
$body = $response->getBody();
|
|
$data = $body->getContents();
|
|
} catch (TransferException $e) {
|
|
return false;
|
|
}
|
|
|
|
$data = json_decode($data,true);
|
|
|
|
if(!$data || !isset($data['code'])){
|
|
$this->error("连接服务器失败");
|
|
}
|
|
|
|
if($data['code'] != 1){
|
|
$this->error($data['msg'],$data['data']);
|
|
}
|
|
|
|
if($type == 'submit'){
|
|
$logModel = new \app\admin\model\channel\submit\Log();
|
|
$logModel->insert([
|
|
'uniacid'=>UNIACID,
|
|
'appid'=>$appid,
|
|
'platform'=>'wechat',
|
|
'version'=>$version,
|
|
'version_desc'=>$desc,
|
|
'system_verison'=>\think\Config::get('license.version'),
|
|
'createtime'=>time()
|
|
]);
|
|
}
|
|
|
|
|
|
$this->success("上传成功",$data['data']);
|
|
}
|
|
|
|
|
|
/**
|
|
* 提交版本
|
|
* @return void
|
|
*/
|
|
public function douyin(){
|
|
set_time_limit(0);
|
|
$version = input('version','1.0.0');
|
|
$desc = input('desc','');
|
|
$type = input('type','submit');
|
|
|
|
if(!$version){
|
|
$this->error("请完善版本号");
|
|
}
|
|
|
|
if(!$desc){
|
|
$this->error("请完善版本描述");
|
|
}
|
|
|
|
if(\app\common\library\Platform::getSystemType() == 'single'){
|
|
$domain = $this->request->domain() . '/';
|
|
}else{
|
|
$domain = $this->request->domain() . '/app/index.php';
|
|
}
|
|
|
|
$dyMiniProgramConfig = \app\common\model\config\System::getConfig('dyMiniProgram');
|
|
|
|
$appid = $dyMiniProgramConfig['appid'];
|
|
$token = $dyMiniProgramConfig['token'];
|
|
|
|
if(!$appid || !$token){
|
|
$this->error("请完善小程序配置信息");
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
$client = \app\common\library\Client::getClient();
|
|
|
|
$response = $client->request("POST",'api/license/upload/douyin',[
|
|
'form_params'=>[
|
|
'version'=>$version,
|
|
'desc'=>$desc,
|
|
'token'=>$token,
|
|
'appid'=>$appid,
|
|
'domain'=>$domain,
|
|
'uniacid'=>UNIACID,
|
|
'actiontype'=>$type
|
|
]
|
|
]);
|
|
$body = $response->getBody();
|
|
$data = $body->getContents();
|
|
} catch (TransferException $e) {
|
|
return false;
|
|
}
|
|
|
|
$data = json_decode($data,true);
|
|
|
|
if(!$data || !isset($data['code'])){
|
|
$this->error("连接服务器失败");
|
|
}
|
|
|
|
if($data['code'] != 1){
|
|
$this->error($data['msg'],$data['data']);
|
|
}
|
|
|
|
if($type == 'submit'){
|
|
$logModel = new \app\admin\model\channel\submit\Log();
|
|
$logModel->insert([
|
|
'uniacid'=>UNIACID,
|
|
'appid'=>$appid,
|
|
'platform'=>'douyin',
|
|
'version'=>$version,
|
|
'version_desc'=>$desc,
|
|
'system_verison'=>\think\Config::get('license.version'),
|
|
'createtime'=>time()
|
|
]);
|
|
}
|
|
|
|
|
|
$this->success("上传成功",$data['data']);
|
|
}
|
|
|
|
|
|
} |