1 line
6.8 KiB
PHP
1 line
6.8 KiB
PHP
<?php
|
|
namespace app\applet\controller\alipay;
|
|
|
|
use app\applet\controller\Controller;
|
|
use app\applet\model\TemplateCode as TemplateCodeModel;
|
|
use app\applet\model\Setting as SettingModel;
|
|
use hema\alipay\Driver;
|
|
use think\facade\View;
|
|
|
|
/**
|
|
* 小程序版本管理
|
|
*/
|
|
class Release extends Controller
|
|
{
|
|
private $config;
|
|
/**
|
|
* 构造方法
|
|
*/
|
|
public function initialize()
|
|
{
|
|
parent::initialize();
|
|
$this->config = $this->getAlipay();
|
|
}
|
|
/**
|
|
* 版本管理
|
|
*/
|
|
public function index()
|
|
{
|
|
$auth = false;
|
|
if(!empty($this->config['app_auth_token'])){
|
|
$auth = true;
|
|
}
|
|
$model = [];
|
|
if($auth){
|
|
//获取平台推送的最新模板代码
|
|
if($result = TemplateCodeModel::getNew($this->app_type,20)){
|
|
$model['code_new'] = $result; //最新模板
|
|
}
|
|
$alipay = new Driver($this->applet_id);
|
|
//线上小程序版本列表
|
|
if($result = $alipay->openMiniVersionListQuery()){
|
|
//如果已有线上版本
|
|
if(isset($result['app_version_infos']) and sizeof($result['app_version_infos'])>0){
|
|
$model['app_version_infos'] = $result['app_version_infos'];
|
|
$model['version'] = $result['app_version_infos'][0];
|
|
//筛选线上版本
|
|
for($n=0;$n<sizeof($model['app_version_infos']);$n++){
|
|
if(in_array($model['app_version_infos'][$n]['version_status'],['RELEASE','OFFLINE','AUDIT_OFFLINE'])){
|
|
$model['online'] = $model['app_version_infos'][$n];
|
|
}
|
|
}
|
|
/*
|
|
version_status参数几个状态
|
|
INIT=开发中
|
|
AUDITING=审核中
|
|
AUDIT_REJECT=审核驳回
|
|
WAIT_RELEASE=待上架
|
|
BASE_AUDIT_PASS=准入不可营销
|
|
GRAY=灰度中
|
|
RELEASE=已上架
|
|
OFFLINE=已下架
|
|
AUDIT_OFFLINE: 已被强制下架
|
|
*/
|
|
}
|
|
}
|
|
}
|
|
return View::fetch('index', compact('auth','model'));
|
|
}
|
|
|
|
/**
|
|
* 上传代码并生成体验版
|
|
*/
|
|
public function commit($id)
|
|
{
|
|
$model = TemplateCodeModel::detail($id);
|
|
$alipay = new Driver($this->applet_id);
|
|
//上传代码
|
|
if(!$alipay->openMiniVersionUpload($model)){
|
|
return $this->renderError($alipay->getError());
|
|
}
|
|
//生成体验版本
|
|
if(!$alipay->openMiniExperienceCreate($model['user_version'])){
|
|
return $this->renderError($alipay->getError());
|
|
}
|
|
return $this->renderSuccess('操作成功', url('alipay.release/index'));
|
|
}
|
|
|
|
/**
|
|
* 获取体验版二维码
|
|
*/
|
|
public function trialQrcode($version)
|
|
{
|
|
$alipay = new Driver($this->applet_id);
|
|
//生成体验版本
|
|
$alipay->openMiniExperienceCreate($version);
|
|
if($model = $alipay->openMiniExperienceQuery($version)){
|
|
return $this->renderSuccess('', '', $model);
|
|
}
|
|
return $this->renderError($alipay->getError());
|
|
}
|
|
|
|
/**
|
|
* 提交代码审核
|
|
* $id=版本号,$speed_up=是否加急
|
|
*/
|
|
public function submitAudit($id,$speed_up='false')
|
|
{
|
|
$values = SettingModel::getItem('ability');
|
|
//审核通过后是否自动上线
|
|
if($values['applet_online'] == 1){
|
|
$auto_online = 'true';
|
|
}else{
|
|
$auto_online = 'false';
|
|
}
|
|
$model = TemplateCodeModel::getCode($this->app_type,$id,20);
|
|
$alipay = new Driver($this->applet_id);
|
|
if(!$alipay->openMiniVersionAuditApply($model,$auto_online,$speed_up)){
|
|
return $this->renderError($alipay->getError());
|
|
}
|
|
return $this->renderSuccess('操作成功', url('alipay.release/index'));
|
|
}
|
|
|
|
/**
|
|
* 撤回代码审核
|
|
*/
|
|
public function undoAudit($id='')
|
|
{
|
|
$alipay = new Driver($this->applet_id);
|
|
if(!$alipay->openMiniVersionAuditCancel($id)){
|
|
return $this->renderError($alipay->getError());
|
|
}
|
|
return $this->renderSuccess('操作成功', url('alipay.release/index'));
|
|
}
|
|
|
|
/**
|
|
* 发布已通过审核的小程序
|
|
*/
|
|
public function release($id)
|
|
{
|
|
$alipay = new Driver($this->applet_id);
|
|
if(!$alipay->openMiniVersionOnline($id)){
|
|
return $this->renderError($alipay->getError());
|
|
}
|
|
return $this->renderSuccess('操作成功', url('alipay.release/index'));
|
|
}
|
|
|
|
/**
|
|
* 退回到开发版本
|
|
*/
|
|
public function auditedCancel($id)
|
|
{
|
|
$alipay = new Driver($this->applet_id);
|
|
if(!$alipay->openMiniVersionAuditedCancel($id)){
|
|
return $this->renderError($alipay->getError());
|
|
}
|
|
return $this->renderSuccess('操作成功', url('alipay.release/index'));
|
|
}
|
|
|
|
/**
|
|
* 发布已通过审核的小程序
|
|
* $version=版本号
|
|
*/
|
|
public function versionDetail($version)
|
|
{
|
|
$alipay = new Driver($this->applet_id);
|
|
if(!$model = $alipay->openMiniVersionDetailQuery($version)){
|
|
return $this->renderError($alipay->getError());
|
|
}
|
|
return $this->renderSuccess('操作成功', '', $model);
|
|
}
|
|
|
|
/**
|
|
* 上架/下架小程序
|
|
* $id=版本号
|
|
* $status=当前状态
|
|
*/
|
|
public function status($id,$status)
|
|
{
|
|
$alipay = new Driver($this->applet_id);
|
|
if($status == 'RELEASE'){
|
|
//下架操作
|
|
if(!$alipay->openMiniVersionOffline($id)){
|
|
return $this->renderError($alipay->getError());
|
|
}
|
|
}else{
|
|
//上架操作
|
|
if(!$alipay->openMiniVersionOnline($id)){
|
|
return $this->renderError($alipay->getError());
|
|
}
|
|
}
|
|
return $this->renderSuccess('操作成功', url('alipay.release/index'));
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 版本回退
|
|
|
|
*/
|
|
|
|
public function fallback()
|
|
|
|
{
|
|
|
|
$wx = new Driver;
|
|
|
|
if ($this->request->isGet()) {
|
|
|
|
//获取可回退的小程序版本
|
|
|
|
if(!$result = $wx->getHistoryVersion($this->applet_id)){
|
|
|
|
return $this->renderError($wx->getError());
|
|
|
|
}
|
|
|
|
$list = $result['version_list'];
|
|
|
|
for($n=0;$n<sizeof($list);$n++){
|
|
|
|
$list[$n]['commit_time'] = date('Y-m-d H:i:s',$list[$n]['commit_time']);
|
|
|
|
}
|
|
|
|
return $this->renderSuccess('', '', compact('list'));
|
|
|
|
}
|
|
|
|
$data = $this->postData('data');
|
|
|
|
// 回退到指定版本
|
|
|
|
if ($wx->revertCodeRelease($this->applet_id,$data['app_version'])) {
|
|
|
|
return $this->renderSuccess('操作成功', url('wxapp.release/index'));
|
|
|
|
}
|
|
|
|
$error = $wx->getError() ?: '操作失败';
|
|
|
|
return $this->renderError($error);
|
|
|
|
}
|
|
|
|
}
|
|
|