911 行
36 KiB
PHP
可执行文件
911 行
36 KiB
PHP
可执行文件
<?php
|
||
|
||
namespace Addons\Api;
|
||
|
||
use Common\Model\AppInfoModel;
|
||
use Common\Model\AppweixinModel;
|
||
use Common\Model\MiniProgramAuthModel;
|
||
use Common\Model\MiniProgramExamineModel;
|
||
use Common\Model\MiniProgramUseModel;
|
||
use Common\Model\WxappinfoModel;
|
||
|
||
//[1.8.73]
|
||
|
||
/**
|
||
* 商城小程序API
|
||
* Class MerXcxConf
|
||
* @package Addons\Api
|
||
*/
|
||
class MerXcxConf
|
||
{
|
||
private $merchant_id; //商户id
|
||
public $errMsg; //错误描述
|
||
|
||
public function __construct($merchant_id)
|
||
{
|
||
$this->merchant_id = $merchant_id;
|
||
}
|
||
|
||
/**
|
||
* 获取基本信息
|
||
*/
|
||
public function getBaseData()
|
||
{
|
||
$AppInfoModel = new WxappinfoModel(); //商户正在使用的小程序
|
||
$map = array(
|
||
'merchant_id' => $this->merchant_id
|
||
);
|
||
$appInfo = $AppInfoModel->getFind($map); //获取小程序信息
|
||
|
||
$examine = array();
|
||
$new_version = 0;
|
||
if (!empty($appInfo)) {
|
||
$examine = $this->getExamineState(); //获取小程序当前审核状态
|
||
$this->modifyDomain(); //设置小程序域名
|
||
}
|
||
$AppWeiXinModel = new AppweixinModel();
|
||
$wxInfo = $AppWeiXinModel->getFind(array('id' => 1));
|
||
$version_name = array(
|
||
'1' => 'default_version_id',
|
||
'2' => 'diy_version_id',
|
||
'3' => 'default_live_version_id',
|
||
'4' => 'diy_live_version_id',
|
||
); // 1普通版(无直播) 2diy版(无直播) 3普通版(有直播) 4diy版(有直播)
|
||
$open_count = 0;
|
||
$preview_code_model = 1;
|
||
if ($wxInfo['diy_live_version_id']) {
|
||
$open_count++;
|
||
$preview_code_model = 4;
|
||
}
|
||
if ($wxInfo['default_live_version_id']) {
|
||
$open_count++;
|
||
$preview_code_model = 3;
|
||
}
|
||
if ($wxInfo['diy_version_id']) {
|
||
$open_count++;
|
||
$preview_code_model = 2;
|
||
}
|
||
if ($wxInfo['default_version_id']) {
|
||
$open_count++;
|
||
$preview_code_model = 1;
|
||
}
|
||
if (!empty($appInfo) && !empty($examine) && $examine['status'] == 4) {
|
||
//判断是否有新版本可更新
|
||
$this_version = $wxInfo[$version_name[$examine['model_type']]];
|
||
$preview_code_model = intval($examine['model_type']);
|
||
if ($examine['template_id'] != $this_version) {
|
||
$new_version = 1;
|
||
}
|
||
} else if (!empty($examine)) {
|
||
$preview_code_model = intval($examine['model_type']);
|
||
}
|
||
return array(
|
||
'status' => 1,
|
||
'msg' => '获取成功',
|
||
'data' => array(
|
||
'preview_code_model' => $preview_code_model,
|
||
'authData' => $appInfo ? $appInfo : array(),
|
||
'examine' => $examine,
|
||
'new_version' => $new_version,
|
||
'open_default' => $wxInfo['default_version_id'] > 0 ? true : false,
|
||
'open_diy' => $wxInfo['diy_version_id'] > 0 ? true : false,
|
||
'open_default_live' => $wxInfo['default_live_version_id'] > 0 ? true : false,
|
||
'open_diy_live' => $wxInfo['diy_live_version_id'] > 0 ? true : false,
|
||
'open_count' => $open_count,
|
||
'online_status' => intval($appInfo['online_status'])
|
||
),
|
||
);
|
||
}
|
||
|
||
/**
|
||
* 获取充值入口显示状态
|
||
*/
|
||
public function changeOnlineStatus()
|
||
{
|
||
$AppInfoModel = new WxappinfoModel(); //商户正在使用的小程序
|
||
$map = array(
|
||
'merchant_id' => $this->merchant_id
|
||
);
|
||
$online_status = I('post.online_status');
|
||
$appInfo = $AppInfoModel->updateOrder($map, array('online_status' => $online_status)); //获取小程序信息
|
||
|
||
if ($appInfo) {
|
||
return array(
|
||
'status' => 1,
|
||
'msg' => '修改成功',
|
||
);
|
||
} else {
|
||
return array(
|
||
'status' => 0,
|
||
'msg' => '修改失败',
|
||
);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 获取小程序体验二维码
|
||
*/
|
||
public function getPreviewQrImg()
|
||
{
|
||
$AppWeiXinModel = new AppweixinModel();
|
||
$template_info = $AppWeiXinModel->getFind(array('id' => 1));
|
||
if (!$template_info) {
|
||
return array(
|
||
'status' => 0,
|
||
'msg' => '系统暂未设置商城小程序模板'
|
||
);
|
||
}
|
||
$this->setWebView();
|
||
//模板id
|
||
$model = I('post.model') ? I('post.model') : 1; //1普通版(无直播) 2diy版(无直播) 3普通版(有直播) 4diy版(有直播)
|
||
$version_name = array(
|
||
'1' => 'default_version_id',
|
||
'2' => 'diy_version_id',
|
||
'3' => 'default_live_version_id',
|
||
'4' => 'diy_live_version_id',
|
||
);
|
||
$template_id = $template_info[$version_name[$model]];
|
||
$map = array(
|
||
'merchant_id' => $this->merchant_id,
|
||
);
|
||
//获取第三方授权的access_token
|
||
$access_token = get_authorizer_access_tokens($this->merchant_id);
|
||
$WxAppInfoModel = new WxappinfoModel();
|
||
$extAppid = $WxAppInfoModel->getFindField($map, 'authorizer_appid');
|
||
$merchant_id_text = "merchant_id";
|
||
$server = 'https://' . $template_info['server'] . "/index.php/SmallProgramApi"; //正式
|
||
$domain = 'https://' . $template_info['server'] . "/index.php"; //正式
|
||
// $server = 'http://' . $template_info['server'] . "/index.php/SmallProgramApi";//线下测试
|
||
if ($model == 3 || $model == 4) {
|
||
//有直播版
|
||
$data = array(
|
||
'template_id' => $template_id,
|
||
"user_version" => "V" . $template_id,
|
||
'ext_json' => "{
|
||
\"extEnable\":true,
|
||
\"extAppid\": \"$extAppid\",
|
||
\"ext\":{\"siteBaseUrl\":\"$server\",\"domain\":\"$domain\",\"appid\":\"$extAppid\",\"$merchant_id_text\":\"$this->merchant_id\"},
|
||
\"plugins\": {\"live-player-plugin\":{\"version\": \"1.2.6\",\"provider\": \"wx2b03c6e691cd7370\"},\"sendCoupon\": {
|
||
\"version\": \"1.1.7\",
|
||
\"provider\": \"wxf3f436ba9bd4be7b\"
|
||
}}
|
||
}",
|
||
"user_desc" => $template_info['information'],
|
||
);
|
||
} else if ($model == 1 || $model == 2) {
|
||
//无直播版
|
||
$data = array(
|
||
'template_id' => $template_id,
|
||
"user_version" => "V" . $template_id,
|
||
'ext_json' => "{
|
||
\"extEnable\":true,
|
||
\"extAppid\": \"$extAppid\",
|
||
\"ext\":{\"siteBaseUrl\":\"$server\",\"domain\":\"$domain\",\"appid\":\"$extAppid\",\"$merchant_id_text\":\"$this->merchant_id\"},
|
||
\"plugins\": {\"sendCoupon\": {
|
||
\"version\": \"1.1.7\",
|
||
\"provider\": \"wxf3f436ba9bd4be7b\"
|
||
}}
|
||
}",
|
||
"user_desc" => $template_info['information'],
|
||
);
|
||
} else {
|
||
return array(
|
||
'status' => 0,
|
||
'msg' => '请求参数有误',
|
||
);
|
||
}
|
||
$data = json_encode($data, JSON_UNESCAPED_UNICODE);
|
||
$url = "https://api.weixin.qq.com/wxa/commit?access_token=" . $access_token;
|
||
$response = curl_get($url, $data);
|
||
$result = json_decode($response, true);
|
||
if ($result["errcode"] == 0 && $result["errmsg"] == "ok") {
|
||
$access_token = get_authorizer_access_tokens($this->merchant_id);
|
||
$url = "https://api.weixin.qq.com/wxa/get_qrcode?access_token=" . $access_token;
|
||
$data = curl_getm($url);
|
||
$path = "./Uploads/App/Code/" . $this->merchant_id;
|
||
if (!is_dir($path)) {
|
||
if (!is_dir('./Uploads/App')) {
|
||
mkdir("./Uploads/App", 0777);
|
||
}
|
||
if (!is_dir('./Uploads/App/Code')) {
|
||
mkdir("./Uploads/App/Code", 0777);
|
||
}
|
||
mkdir("./Uploads/App/Code/" . $this->merchant_id, 0777);
|
||
} else {
|
||
$p = scandir($path);
|
||
foreach ($p as $val) {
|
||
if ($val != "." && $val != "..") {
|
||
unlink($path . '/' . $val);
|
||
}
|
||
}
|
||
}
|
||
$file_name = $path . '/' . rand(1000, 9999) . 'qrcode.jpg';
|
||
if (file_put_contents($file_name, $data)) {
|
||
return array(
|
||
'status' => 1,
|
||
'msg' => '获取成功',
|
||
'preview_path' => substr($file_name, 1),
|
||
);
|
||
}
|
||
} else {
|
||
return array(
|
||
'status' => 0,
|
||
'msg' => $result["errmsg"]
|
||
);
|
||
}
|
||
}
|
||
/**
|
||
* 设置小程序用户隐私保护指引
|
||
*/
|
||
public function setPrivacySetting(){
|
||
$data = array(
|
||
'privacy_ver' => 2,
|
||
'setting_list' => array(
|
||
array(
|
||
"privacy_key" => 'Location',
|
||
"privacy_text" => '获取离您最近的门店'
|
||
),
|
||
array(
|
||
"privacy_key" => 'AlbumWriteOnly',
|
||
"privacy_text" => '保存图片或者上传图片'
|
||
),
|
||
array(
|
||
"privacy_key" => 'PhoneNumber',
|
||
"privacy_text" => '在必要时和用户联系'
|
||
),
|
||
array(
|
||
"privacy_key" => 'UserInfo',
|
||
"privacy_text" => '分辨用户'
|
||
)
|
||
),
|
||
'owner_setting' => array(
|
||
'contact_phone' => '18778995730',
|
||
'notice_method' => '通过公告联系'
|
||
)
|
||
);
|
||
$access_token = get_authorizer_access_tokens($this->merchant_id);
|
||
$url = 'https://api.weixin.qq.com/cgi-bin/component/setprivacysetting?access_token=' . $access_token;
|
||
$data = json_encode($data, JSON_UNESCAPED_UNICODE);
|
||
$response = curl_get($url, $data);
|
||
$response = json_decode($response, true);
|
||
return $response;
|
||
}
|
||
/**
|
||
* 检查小程序审核状态
|
||
* @return mixed
|
||
*/
|
||
public function getExamineState()
|
||
{
|
||
$MiniProgramExamineModel = new MiniProgramExamineModel();
|
||
$map = array(
|
||
'merchant_id' => $this->merchant_id,
|
||
'state' => 1,
|
||
);
|
||
$history = $MiniProgramExamineModel->getFind($map, '*', 'id desc');
|
||
if (!empty($history)) {
|
||
if ($history['status'] == 2) {
|
||
$access_token = get_authorizer_access_tokens($this->merchant_id);
|
||
if (!empty($history['audit_id'])) {
|
||
$requestData = array(
|
||
'auditid' => $history['audit_id'],
|
||
);
|
||
$url = "https://api.weixin.qq.com/wxa/get_auditstatus?access_token=" . $access_token;
|
||
$response = http_request($url, json_encode($requestData));
|
||
} else {
|
||
$url = "https://api.weixin.qq.com/wxa/get_latest_auditstatus?access_token=" . $access_token;
|
||
$response = curl_getm($url);
|
||
}
|
||
$response = json_decode($response, true);
|
||
//审核状态 0审核通过 1审核驳回 2审核中 3撤回审核 4发布成功
|
||
if ($response['errcode'] == '0' && $history['status'] != $response['status']) {
|
||
$save = array(
|
||
'status' => $response['status'],
|
||
);
|
||
$history['status'] = $response['status'];
|
||
if ($response['status'] == 1) {
|
||
$reason = str_replace(array("\r\n", "\r", "\n", "<br>"), "", $response["reason"]);
|
||
$save['reject_msg'] = $reason;
|
||
$history['reject_msg'] = $reason;
|
||
}
|
||
if (empty($history['audit_id'])) {
|
||
$save['audit_id'] = $response['auditid'];
|
||
}
|
||
$MiniProgramExamineModel->updateOrder(array('id' => $history['id']), $save);
|
||
}
|
||
}
|
||
} else {
|
||
$history = array();
|
||
}
|
||
return $history;
|
||
}
|
||
|
||
/**
|
||
* 域名参数设置 小程序模板开发设置安全域名
|
||
*/
|
||
public function modifyDomain()
|
||
{
|
||
$access_token = get_authorizer_access_tokens($this->merchant_id);
|
||
$url = "https://api.weixin.qq.com/wxa/modify_domain?access_token=" . $access_token;
|
||
$AppWeiXinModel = new AppweixinModel();
|
||
$cache = $AppWeiXinModel->getFind(array('id' => 1));
|
||
$data = array(
|
||
"action" => "add",
|
||
"requestdomain" => array("https://" . $cache['server']),
|
||
"wsrequestdomain" => array("wss://" . $cache['server'] . ":7282"),
|
||
"uploaddomain" => array("https://" . $cache['server']),
|
||
"downloaddomain" => array("https://" . $cache['server']),
|
||
);
|
||
|
||
$data = json_encode($data, JSON_UNESCAPED_SLASHES);
|
||
$response = curl_get($url, $data);
|
||
$result = json_decode($response, true);
|
||
}
|
||
|
||
/**
|
||
* 小程序的授权功能 准备跳转授权页面
|
||
* @param $redirect_url
|
||
* @return string
|
||
*/
|
||
public function authIndex($redirect_url)
|
||
{
|
||
$AppWeiXinModel = new AppweixinModel();
|
||
$appid = $AppWeiXinModel->getFindField(array('id' => 1), 'appid');
|
||
|
||
$access = get_acc_token();
|
||
$url = 'https://api.weixin.qq.com/cgi-bin/component/api_create_preauthcode?component_access_token=' . $access;
|
||
$data = array(
|
||
'component_appid' => $appid
|
||
);
|
||
$postData = json_encode($data);
|
||
$response = curl_get($url, $postData);
|
||
$result = json_decode($response, true);
|
||
|
||
$save = array(
|
||
'component_access_token' => $access,
|
||
'pre_auth_code' => $result['pre_auth_code']
|
||
);
|
||
$AppWeiXinModel->updateOrder(array('id' => 1), $save); //保存到数据库
|
||
//点击授权
|
||
$pre_auth_code = $result['pre_auth_code'];
|
||
$http_type = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on')
|
||
|| (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://';
|
||
$redirect_uri = $http_type . C("adminhttp") . '/index.php/' . $redirect_url . '/merchant_id/' . $this->merchant_id;
|
||
$urls = 'https://mp.weixin.qq.com/cgi-bin/componentloginpage?component_appid=' . $appid . '&auth_type=2&pre_auth_code=' . $pre_auth_code . '&redirect_uri=' . $redirect_uri;
|
||
return $urls;
|
||
}
|
||
|
||
/**
|
||
* 小程序授权回调处理
|
||
* @return bool
|
||
*/
|
||
public function authSuccess()
|
||
{
|
||
//这个方法是参看授权状态并且提交授权信息的
|
||
$AppWeiXinModel = new AppweixinModel();
|
||
$wxInfo = $AppWeiXinModel->getFind(array('id' => 1));
|
||
if ($_GET['auth_code']) {
|
||
$appid = $wxInfo['appid'];
|
||
$access = get_acc_token();
|
||
//获取第三方接口调用凭据
|
||
$url = 'https://api.weixin.qq.com/cgi-bin/component/api_query_auth?component_access_token=' . $access;
|
||
$data = array(
|
||
'component_appid' => $appid,
|
||
'authorization_code' => $_GET['auth_code']
|
||
);
|
||
$data = json_encode($data);
|
||
$response = curl_get($url, $data);
|
||
$result = json_decode($response, true);
|
||
$access = false;
|
||
foreach ($result['authorization_info']['func_info'] as $val) {
|
||
if ($val["funcscope_category"]["id"] == 18) {
|
||
$access = true;
|
||
break;
|
||
}
|
||
}
|
||
if (!$access) {
|
||
$this->errMsg = '该小程序没有开发管理权限,登录小程序后台清除所有第三方授权,然后重新授权';
|
||
return false;
|
||
}
|
||
$authorizer_appid = $result['authorization_info']['authorizer_appid'];
|
||
$item = $this->get_authorizer_info($authorizer_appid); //获取小程序详细信息
|
||
$item['authorizer_appid'] = $authorizer_appid;
|
||
$item['authorizer_access_token'] = $result['authorization_info']['authorizer_access_token'];
|
||
$item['authorizer_refresh_token'] = $result['authorization_info']['authorizer_refresh_token'];
|
||
$item['access_token_time'] = time();
|
||
|
||
$AppInfoModel = new WxappinfoModel();
|
||
//小程序绑定验重
|
||
$repeatMap = [
|
||
'authorizer_appid' => $item['authorizer_appid'],
|
||
'merchant_id' => ['neq', $this->merchant_id],
|
||
];
|
||
$repeat = $AppInfoModel->getFind($repeatMap);
|
||
if ($repeat) {
|
||
$this->errMsg = '该系统已有商户使用该小程序,请更换其他小程序';
|
||
return false;
|
||
}
|
||
$map = array(
|
||
'merchant_id' => $this->merchant_id
|
||
);
|
||
// 判断当前用户是否授权或者设置过授权信息
|
||
$appInfo = $AppInfoModel->getFind($map);
|
||
if (empty($appInfo)) {
|
||
//添加一个小程序的配置信息
|
||
$item['merchant_id'] = $this->merchant_id;
|
||
$AppInfoModel->addOrder($item);
|
||
} else {
|
||
$AppInfoModel->updateOrder($map, $item);
|
||
}
|
||
$ProgramAuthModel = new MiniProgramAuthModel();
|
||
$aMap = array(
|
||
'merchant_id' => $this->merchant_id,
|
||
'status' => 1,
|
||
);
|
||
$ProgramAuthModel->updateOrder($aMap, array('status' => 0)); //把之前的授权记录改为不启用
|
||
|
||
$aItem = array(
|
||
'merchant_id' => $this->merchant_id,
|
||
'status' => 1,
|
||
'appid' => $item['authorizer_appid'],
|
||
'add_time' => time(),
|
||
'program_name' => $item['nick_name'],
|
||
'operator_id' => session('jurisdiction_user')['id'],
|
||
);
|
||
$add = $ProgramAuthModel->addOrder($aItem); //新增一条授权记录
|
||
if (!empty($appInfo) && $appInfo['authorizer_appid'] != $item['authorizer_appid']) {
|
||
//授权的是新的小程序
|
||
$MiniProgramExamineModel = new MiniProgramExamineModel();
|
||
$mMap = array(
|
||
'merchant_id' => $this->merchant_id,
|
||
'id' => array('neq', $add),
|
||
'state' => 1
|
||
);
|
||
$MiniProgramExamineModel->updateOrder($mMap, array('state' => 0)); //把之前的审核中的记录状态改为旧版
|
||
}
|
||
return true;
|
||
} else {
|
||
$this->errMsg = '系统暂未添加商城小程序';
|
||
return false;
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 获取小程序的详情信息
|
||
*/
|
||
public function get_authorizer_info($authorizer_appid)
|
||
{
|
||
$AppWeiXinModel = new AppweixinModel();
|
||
$appid = $AppWeiXinModel->getFindField(array('id' => 1), 'appid');
|
||
$access = get_acc_token();
|
||
// 获取授权方的账号基本信息
|
||
$url = 'https://api.weixin.qq.com/cgi-bin/component/api_get_authorizer_info?component_access_token=' . $access;
|
||
$data = array(
|
||
'component_appid' => $appid,
|
||
'authorizer_appid' => $authorizer_appid
|
||
);
|
||
$data = json_encode($data);
|
||
$response = curl_get($url, $data);
|
||
$result = json_decode($response, true);
|
||
// 插入数据库
|
||
$info['nick_name'] = $result['authorizer_info']['nick_name'];
|
||
$info['head_img'] = $result['authorizer_info']['head_img'];
|
||
$info['service_type_info'] = $result['authorizer_info']['service_type_info']['id'];
|
||
$info['user_name'] = $result['authorizer_info']['user_name'];
|
||
$info['signature'] = $result['authorizer_info']['signature'];
|
||
$info['principal_name'] = $result['authorizer_info']['principal_name'];
|
||
$info['qrcode_url'] = $result['authorizer_info']['qrcode_url'];
|
||
return $info;
|
||
}
|
||
|
||
/**
|
||
* 小程序提交审核
|
||
* @param int $urgent_state 0不加急 1加急审核
|
||
* @return array
|
||
*/
|
||
public function submitAudit($urgent_state = 0)
|
||
{
|
||
$model = I('post.model') ? I('post.model') : 1; //1普通版(无直播) 2diy版(无直播) 3普通版(有直播) 4diy版(有直播)
|
||
$setPreview = $this->getPreviewQrImg();
|
||
if ($setPreview['status'] == 0) {
|
||
return $setPreview;
|
||
}
|
||
$this->setWebView(); //设置小程序web-view域名
|
||
$AppWeiXinModel = new AppweixinModel();
|
||
$field = array(
|
||
'default_version_id',
|
||
'diy_version_id',
|
||
'default_live_version_id',
|
||
'diy_live_version_id',
|
||
);
|
||
$app = $AppWeiXinModel->getFind(array('id' => 1), $field);
|
||
$version_name = array(
|
||
'1' => 'default_version_id',
|
||
'2' => 'diy_version_id',
|
||
'3' => 'default_live_version_id',
|
||
'4' => 'diy_live_version_id',
|
||
);
|
||
$template_id = $app[$version_name[$model]];
|
||
$tags = $app['tag'];
|
||
|
||
$appPage = $this->getPage(); //获取配置页面
|
||
if ($appPage['status'] != 1) {
|
||
return $appPage;
|
||
}
|
||
$address = $appPage['page_list'];
|
||
|
||
$appCategory = $this->getCategory();
|
||
if ($appCategory['status'] != 1) {
|
||
return $appCategory;
|
||
}
|
||
$categoryList = $appCategory['category_list'];
|
||
if (count($categoryList) > 1) {
|
||
$data = array(
|
||
'item_list' => array(
|
||
array(
|
||
"address" => $address[0],
|
||
"tag" => $tags,
|
||
"first_class" => $categoryList[0]['first_class'],
|
||
"second_class" => $categoryList[0]['second_class'],
|
||
"first_id" => $categoryList[0]['first_id'],
|
||
"second_id" => $categoryList[0]['second_id'],
|
||
"title" => "首页"
|
||
), array(
|
||
"address" => $address[1],
|
||
"tag" => $tags,
|
||
"first_class" => $categoryList[1]['first_class'],
|
||
"second_class" => $categoryList[1]['second_class'],
|
||
"first_id" => $categoryList[1]['first_id'],
|
||
"second_id" => $categoryList[1]['second_id'],
|
||
"title" => "功能页面"
|
||
),
|
||
),
|
||
'order_path' => 'pages/myOrder/myOrder'
|
||
);
|
||
} else {
|
||
$data = array(
|
||
'item_list' => array(
|
||
array(
|
||
"address" => $address[0],
|
||
"tag" => $tags,
|
||
"first_class" => $categoryList[0]['first_class'],
|
||
"second_class" => $categoryList[0]['second_class'],
|
||
"first_id" => $categoryList[0]['first_id'],
|
||
"second_id" => $categoryList[0]['second_id'],
|
||
"title" => "首页"
|
||
)
|
||
),
|
||
'order_path' => 'pages/myOrder/myOrder'
|
||
);
|
||
}
|
||
$access_token = get_authorizer_access_tokens($this->merchant_id);
|
||
$url = 'https://api.weixin.qq.com/wxa/submit_audit?access_token=' . $access_token;
|
||
$data = json_encode($data, JSON_UNESCAPED_UNICODE);
|
||
$response = curl_get($url, $data);
|
||
$response = json_decode($response, true);
|
||
// 如果提交成功插入数据 跳转页面
|
||
if ($response['errmsg'] == "ok" || $response["errcode"] == 85009) {
|
||
//数据库插入一条提交审核记录
|
||
//获取版本信息
|
||
$MiniProgramUseModel = new MiniProgramUseModel();
|
||
$uMap = array(
|
||
'template_id' => $template_id,
|
||
'type' => $model,
|
||
);
|
||
$versionInfo = $MiniProgramUseModel->getOrderFind($uMap, '*', 'id desc');
|
||
if (empty($versionInfo)) {
|
||
$access_token = get_acc_token();
|
||
$url = "https://api.weixin.qq.com/wxa/gettemplatelist?access_token=" . $access_token;
|
||
$responses = curl_get($url);
|
||
$results = json_decode($responses, true);
|
||
foreach ($results['template_list'] as $v) {
|
||
if ($template_id == $v['template_id']) {
|
||
$user_version = $v['user_version'];
|
||
$user_desc = $v['user_desc'];
|
||
break;
|
||
}
|
||
}
|
||
} else {
|
||
$user_version = $versionInfo['user_version'];
|
||
$user_desc = $versionInfo['user_desc'];
|
||
}
|
||
|
||
$aMap = array(
|
||
'merchant_id' => $this->merchant_id
|
||
);
|
||
$AppInfoModel = new WxappinfoModel();
|
||
$appInfo = $AppInfoModel->getFind($aMap);
|
||
$history = array(
|
||
'merchant_id' => $this->merchant_id,
|
||
'version_info' => $user_desc,
|
||
'version' => $user_version,
|
||
'template_id' => $template_id,
|
||
'program_name' => $appInfo['nick_name'],
|
||
'appid' => $appInfo['authorizer_appid'],
|
||
'audit_id' => $response['auditid'],
|
||
'add_time' => time(),
|
||
'status' => 2,
|
||
'state' => 1,
|
||
'submit_operator_id' => session('jurisdiction_user')['id'],
|
||
'model_type' => $model,
|
||
);
|
||
$MiniProgramExamineModel = new MiniProgramExamineModel();
|
||
$MiniProgramExamineModel->updateOrder(array('merchant_id' => $this->merchant_id), array('state' => 0)); //把之前的审核中的记录状态改为旧版
|
||
$add = $MiniProgramExamineModel->addOrder($history); //新增提交审核记录
|
||
$history['id'] = $add;
|
||
if ($urgent_state == 1) {
|
||
//加急审核
|
||
$res = $this->sendUrgentAudit($history['id'], $history['audit_id']);
|
||
if ($res['status'] == 1) {
|
||
$msg = '提交审核成功';
|
||
} else {
|
||
$msg = '版本审核提交成功,加急审核提交失败';
|
||
}
|
||
return array(
|
||
'msg' => $msg,
|
||
'status' => 1,
|
||
'data' => $history,
|
||
'res' => $res,
|
||
);
|
||
} else {
|
||
return array(
|
||
'msg' => '提交审核成功',
|
||
'status' => 1,
|
||
'data' => $history,
|
||
);
|
||
}
|
||
} else {
|
||
return array(
|
||
'msg' => $response['errmsg'],
|
||
'status' => 0,
|
||
'data' => $response
|
||
);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 提交加急审核请求
|
||
* @param $examine_id 审核记录id
|
||
* @param $audit_id 微信官方审核单id
|
||
* @return mixed
|
||
*/
|
||
public function sendUrgentAudit($examine_id, $audit_id)
|
||
{
|
||
$requestData = array(
|
||
'auditid' => $audit_id,
|
||
);
|
||
$access_token = get_acc_token();
|
||
$url = "https://api.weixin.qq.com/wxa/speedupaudit?access_token=" . $access_token;
|
||
$response = http_request($url, json_encode($requestData));
|
||
$response = json_decode($response, true);
|
||
if ($response['errcode'] == '0') {
|
||
$save = array(
|
||
'urgent_audit' => 1,
|
||
);
|
||
$MiniProgramExamineModel = new MiniProgramExamineModel();
|
||
$MiniProgramExamineModel->updateOrder(array('id' => $examine_id), $save);
|
||
$res['status'] = 1;
|
||
$res['msg'] = '加急审核提交成功';
|
||
} else {
|
||
$res['status'] = 0;
|
||
$res['msg'] = $response['errmsg'] ? $response['errmsg'] : '请求发生错误';
|
||
$res['data'] = $response;
|
||
}
|
||
return $res;
|
||
}
|
||
|
||
/**
|
||
* 设置小程序web-view域名
|
||
*/
|
||
public function setWebView()
|
||
{
|
||
$access_token = get_authorizer_access_tokens($this->merchant_id, 1);
|
||
$url = "https://api.weixin.qq.com/wxa/setwebviewdomain?access_token=" . $access_token;
|
||
$data['action'] = "add";
|
||
$data['webviewdomain'] = array("https://" . C("adminhttp"));
|
||
$data = json_encode($data, JSON_UNESCAPED_UNICODE);
|
||
$response = curl_get($url, $data);
|
||
}
|
||
|
||
/**
|
||
* 获取配置页面
|
||
*/
|
||
public function getPage()
|
||
{
|
||
$access_token = get_authorizer_access_tokens($this->merchant_id);
|
||
$url = "https://api.weixin.qq.com/wxa/get_page?access_token=" . $access_token;
|
||
$data = curl_getm($url);
|
||
//显示获得的数据
|
||
$data = json_decode($data, true);
|
||
if ($data['errmsg'] == "ok") {
|
||
return array(
|
||
'status' => 1,
|
||
'page_list' => $data['page_list'],
|
||
);
|
||
} else {
|
||
return array(
|
||
'status' => 0,
|
||
'msg' => "获取小程序的第三方提交代码的页面配置接口错误:" . $data['errmsg'],
|
||
);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 获取小程序的授权目录
|
||
* @return array
|
||
*/
|
||
public function getCategory()
|
||
{
|
||
$access_token = get_authorizer_access_tokens($this->merchant_id);
|
||
$url = "https://api.weixin.qq.com/wxa/get_category?access_token=" . $access_token;
|
||
$data = curl_getm($url);
|
||
//显示获得的数据
|
||
$data = json_decode($data, true);
|
||
if ($data['errmsg'] == "ok") {
|
||
return array(
|
||
'status' => 1,
|
||
'category_list' => $data['category_list']
|
||
);
|
||
} else {
|
||
return array(
|
||
'status' => 0,
|
||
'msg' => "获取授权小程序帐号的可选类目:" . $data['errmsg']
|
||
);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 绑定开发体验用户
|
||
*/
|
||
public function bindUser()
|
||
{
|
||
$id = I('post.id');
|
||
$access_token = get_authorizer_access_tokens($this->merchant_id);
|
||
$url = "https://api.weixin.qq.com/wxa/bind_tester?access_token=" . $access_token;
|
||
$data = array(
|
||
'wechatid' => $id,
|
||
);
|
||
$data = json_encode($data);
|
||
$response = curl_get($url, $data);
|
||
$response = json_decode($response, true);
|
||
if ($response['errcode'] == 0) {
|
||
$res['status'] = 1;
|
||
$res['msg'] = "添加成功";
|
||
} else {
|
||
$res['status'] = 0;
|
||
$res['msg'] = "添加失败,请检查微信号是否正常";
|
||
$res['data'] = $response;
|
||
}
|
||
return $res;
|
||
}
|
||
|
||
/**
|
||
* 小程序审核撤回
|
||
*/
|
||
public function undoCodeAudit()
|
||
{
|
||
$access_token = get_authorizer_access_tokens($this->merchant_id);
|
||
$url = "https://api.weixin.qq.com/wxa/undocodeaudit?access_token=" . $access_token;
|
||
$response = curl_getm($url);
|
||
$response = json_decode($response, true);
|
||
if ($response['errcode'] == 0) {
|
||
$res['status'] = 1;
|
||
$res['msg'] = "审核撤回成功";
|
||
$MiniProgramExamineModel = new MiniProgramExamineModel();
|
||
$map = array(
|
||
'merchant_id' => $this->merchant_id,
|
||
'state' => 1,
|
||
);
|
||
$history = $MiniProgramExamineModel->getFind($map, '*', 'id desc');
|
||
if ($history['status'] != 3) {
|
||
$save = array(
|
||
'status' => 3,
|
||
'revoke_time' => time(),
|
||
'reject_operator_id' => session('jurisdiction_user')['id'],
|
||
);
|
||
$MiniProgramExamineModel->updateOrder(array('id' => $history['id']), $save);
|
||
}
|
||
} else {
|
||
if ($response['errcode'] == 87013) {
|
||
$str = "撤回次数达到上限(每天一次,每个月 10 次),错误码:" . $response['errcode'];
|
||
} else {
|
||
$str = "未知错误" . $response['errcode'];
|
||
}
|
||
$res['status'] = 0;
|
||
$res['msg'] = "审核撤回失败,错误原因:" . $str;
|
||
}
|
||
return $res;
|
||
}
|
||
|
||
/**
|
||
* 发布小程序版本
|
||
*/
|
||
public function release()
|
||
{
|
||
$access_token = get_authorizer_access_tokens($this->merchant_id);
|
||
$url = "https://api.weixin.qq.com/wxa/release?access_token=" . $access_token;
|
||
|
||
$response = curl_get($url, "{}");
|
||
$result = json_decode($response, true);
|
||
if ($result['errmsg'] == "ok") {
|
||
$MiniProgramExamineModel = new MiniProgramExamineModel();
|
||
$map = array(
|
||
'merchant_id' => $this->merchant_id,
|
||
'status' => 0,
|
||
'state' => 1,
|
||
);
|
||
$history = $MiniProgramExamineModel->getFind($map, '*', 'id desc');
|
||
$save = array(
|
||
'status' => 4,
|
||
'release_time' => time(),
|
||
);
|
||
$MiniProgramExamineModel->updateOrder(array('id' => $history['id']), $save);
|
||
return array('msg' => "发布成功", 'status' => 1);
|
||
} else if ($result['errcode'] == "85020") {
|
||
return array('msg' => "小程序状态错误,请重新审核提交", 'status' => 0);
|
||
} else if ($result['errcode'] == "85052") {
|
||
return array('msg' => "小程序已经发布过了", 'status' => 0);
|
||
} else {
|
||
return array('msg' => "发布失败,错误原因" . $response, 'status' => 0);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 小程序版本回退 只能回退一个版本
|
||
* @return array
|
||
*/
|
||
public function reBack()
|
||
{
|
||
$access_token = get_authorizer_access_tokens($this->merchant_id);
|
||
$url = "https://api.weixin.qq.com/wxa/revertcoderelease?access_token=" . $access_token;
|
||
|
||
$response = curl_getm($url);
|
||
$result = json_decode($response, true);
|
||
if ($result['errmsg'] == "ok") {
|
||
$MiniProgramExamineModel = new MiniProgramExamineModel();
|
||
$map = array(
|
||
'merchant_id' => $this->merchant_id,
|
||
'status' => 4,
|
||
'state' => 1,
|
||
);
|
||
$history = $MiniProgramExamineModel->getFind($map, '*', 'id desc');
|
||
$save = array(
|
||
'status' => 0,
|
||
'state' => 0,
|
||
);
|
||
$MiniProgramExamineModel->updateOrder(array('id' => $history['id']), $save);
|
||
$map = array(
|
||
'merchant_id' => $this->merchant_id,
|
||
'status' => 4,
|
||
'id' => array('lt', $history['id'])
|
||
);
|
||
$old = $MiniProgramExamineModel->getFind($map, 'id', 'id desc');
|
||
$save = array(
|
||
'status' => 4,
|
||
'state' => 1,
|
||
);
|
||
$MiniProgramExamineModel->updateOrder(array('id' => $old['id']), $save);
|
||
return array('msg' => "回退成功", 'status' => 1);
|
||
} else if ($result['errcode'] == "87011") {
|
||
return array('msg' => "现网已经在灰度发布,不能进行版本回退", 'status' => 0);
|
||
} else if ($result['errcode'] == "87012") {
|
||
return array('msg' => "该版本不能回退,可能的原因:1:无上一个线上版用于回退 2:此版本为已回退版本,不能回退 3:此版本为回退功能上线之前的版本,不能回退", 'status' => 0);
|
||
} else {
|
||
return array('msg' => "回退失败,错误原因" . $response, 'status' => 0);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 清除小程序授权记录
|
||
* @return mixed
|
||
*/
|
||
public function clearAuthInfo(){
|
||
$AppInfoModel = new AppInfoModel();
|
||
$res = $AppInfoModel->deleteOrder(['merchant_id' => $this->merchant_id]);
|
||
if ($res) {
|
||
return callBack(statusCode()['success'], '清除成功');
|
||
} else {
|
||
return callBack(statusCode()['error'], '清除失败');
|
||
}
|
||
}
|
||
}
|