onlineUserId = $onlineUserId; $this->onlineEnterpriseId = $enterpriseId; $this->areaCode = $areaCode; $this->objDEnterpriseBindTemplate = new DEnterpriseBindTemplate('default'); $this->objDSystemTemplate = new DSystemTemplate(); } /** * 企业选择模版启用/停用 * @param $params * @return ResultWrapper */ public function bindTemplate($params, $token) { // 启用得微信模板id $weixinTemplateId = $params['weixinTemplateId']; unset($params['weixinTemplateId']); $oplatformConfigData = Factory::config()->getAppoint('weixin', 'oplatform'); if (empty($oplatformConfigData)) { exit('配置错误'); } // 获取当前登录企业的小程序配置 $objSystemCache = new SystemCache(); $miniprogramSetting = $objSystemCache->getAppIdByEnterpriseId($this->onlineEnterpriseId); if (empty($miniprogramSetting)) { return ResultWrapper::fail('后台小程序配置项为空', ErrorCode::$configEroor); } $miniprogramSetting = json_decode($miniprogramSetting, true); // 企业设置的小程序id $authorizer_appid = $miniprogramSetting['appid']; $ext_json = [ 'extEnable' => 'true', 'extAppid' => $miniprogramSetting['appid'], 'directCommit' => false, 'ext' => [ 'token' => $token, ], ]; $objOplatform = new Oplatform($oplatformConfigData['appid'], $oplatformConfigData['token'], $oplatformConfigData['encodingAesKey'], $oplatformConfigData['appSecret']); // 1.上传小程序 $result = $objOplatform->commit($authorizer_appid, $weixinTemplateId, $ext_json, '1.0', '切换模板'); if (!$result->isSuccess()) { return ResultWrapper::fail($result->getData(), $result->getErrorCode()); } // 2.获取已上传的代码的页面列表 unset($result); $result = $objOplatform->getPage($authorizer_appid); if (!$result->isSuccess()) { return ResultWrapper::fail($result->getData(), $result->getErrorCode()); } $pageList = $result->getData(); // 3.获取的体验版二维码 unset($result); $result = $objOplatform->getQrcode($authorizer_appid, $pageList[0]); if (!$result->isSuccess()) { return ResultWrapper::fail($result->getData(), $result->getErrorCode()); } if (!is_dir(UPLOAD_FILE_PATH)) { mkdir(UPLOAD_FILE_PATH, 0777, true); } if (!file_put_contents(UPLOAD_FILE_PATH . $authorizer_appid . '.jpeg', $result->getData())) { return ResultWrapper::fail('保存体验二维码失败', ErrorCode::$contentNotExists); } //关闭其他所有开启的模版 $dbResult = $this->objDEnterpriseBindTemplate->update(['enableStatus' => StatusCode::$delete], ['enterpriseId' => $this->onlineEnterpriseId, 'enableStatus' => StatusCode::$standard]); if ($dbResult === false) { return ResultWrapper::fail($this->objDEnterpriseBindTemplate->error(), ErrorCode::$dberror); } $params['auditStatus'] = StatusCode::$wxAuditStatus['inAudit']; $params['qrcodeImg'] = URL_UPLOAD . $authorizer_appid . '.jpeg'; $dbResult = $this->objDEnterpriseBindTemplate->replace($params); if ($dbResult === false) { return ResultWrapper::fail($this->objDEnterpriseBindTemplate->error(), ErrorCode::$dberror); } //提交审核 $dbResult = self::submitAudit($params); if (!$dbResult->isSuccess()) { return ResultWrapper::fail($this->objDEnterpriseBindTemplate->error(), ErrorCode::$dberror); } return ResultWrapper::success('上传代码成功'); } /** * 获取企业正在使用的模版 * @return ResultWrapper */ public function getAllTemplate() { $objDSystemTemplate = new DSystemTemplate(); $dbResult = $objDSystemTemplate->select(['deleteStatus' => StatusCode::$standard], 'id,title,weixinTemplateId,type,version'); if ($dbResult === false) { return ResultWrapper::fail($objDSystemTemplate->error(), ErrorCode::$dberror); } $templateIData = $this->objDEnterpriseBindTemplate->get(['enterpriseId' => $this->onlineEnterpriseId, 'enableStatus' => StatusCode::$standard], 'auditId,version,auditStatus,reason,templateId,enterpriseId,status,qrcodeImg'); if ($templateIData === false) { return ResultWrapper::fail($this->objDEnterpriseBindTemplate->error(), ErrorCode::$dberror); } foreach ($dbResult as &$template) { $template['isVersion'] = StatusCode::$standard; $template['enableStatus'] = StatusCode::$delete; $template['qrcodeImg'] = ''; $template['auditStatus'] = StatusCode::$wxAuditStatus['beenRelease']; if (!empty($templateIData)) { if ($template['id'] == $templateIData['templateId']) { if ($templateIData['version'] != $template['version']) { $template['isVersion'] = StatusCode::$delete;//有新版本 } $template['reason'] = isset($templateIData['reason']) && !empty($templateIData['reason']) ? json_decode($templateIData['reason'], true) : ''; $template['auditId'] = isset($templateIData['auditId']) ? $templateIData['auditId'] : ''; $template['auditStatus'] = isset($templateIData['auditStatus']) ? $templateIData['auditStatus'] : ''; $template['enableStatus'] = StatusCode::$standard; //$template['status'] = $templateIData['status']; $template['qrcodeImg'] = $templateIData['qrcodeImg']; } } } $total = $this->objDEnterpriseBindTemplate->count(['enterpriseId' => $this->onlineEnterpriseId, 'enableStatus' => StatusCode::$standard]); $return = [ 'data' => $dbResult, 'total' => ($total) ? intval($total) : 0, ]; return ResultWrapper::success($return); } /** * 获取首页模版及数据 * @return ResultWrapper * @throws \Exception * @deprecated */ public function getTemplate() { $templateId = $this->objDEnterpriseBindTemplate->get_field('templateId', ['enterpriseId' => $this->onlineEnterpriseId, 'enableStatus' => StatusCode::$standard]); if ($templateId === false) { return ResultWrapper::fail($this->objDEnterpriseBindTemplate->error(), ErrorCode::$dberror); } if (empty($templateId)) { return ResultWrapper::fail('当前企业没有正在使用的模版', ErrorCode::$dberror); } $type = $this->objDSystemTemplate->get_field('type', ['id' => $templateId]); if ($type === false) { return ResultWrapper::fail($this->objDSystemTemplate->error(), ErrorCode::$dberror); } if (empty($type)) { return ResultWrapper::fail('获取模版失败', ErrorCode::$paramError); } $allModuleData = []; switch ($type) { case StatusCode::$templateType['ordinary']: //普通模版 //获取该模版平台设置的模块 $objDTemplateModule = new DTemplateModule(); $module = $objDTemplateModule->select(['templateId' => $templateId, 'enableStatus' => StatusCode::$standard]); if ($module === false) { return ResultWrapper::fail($objDTemplateModule->error(), ErrorCode::$dberror); } //获取该企业下显示的模块,模块下的数据 $objMEnterpriseTemplateModule = new MEnterpriseTemplateModule($this->onlineUserId, $this->onlineEnterpriseId); $moduleData = $objMEnterpriseTemplateModule->getModuleByIds(['templateId' => $templateId, 'moduleId' => array_column($module, 'id')]); //验证商品有效性 $moduleData = self::checkModule($moduleData); foreach ($module as $key => $val) { $allModuleData[$val['alias']] = [ 'moduleAlias' => $val['alias'], 'enableStatus' => isset($moduleData[$val['alias']]['enableStatus']) ? $moduleData[$val['alias']]['enableStatus'] : StatusCode::$standard, 'moduleData' => isset($moduleData[$val['alias']]['moduleData']) ? json_decode($moduleData[$val['alias']]['moduleData'], true) : [], ]; } break; case StatusCode::$templateType['universal']: //万能模版 $objMPage = new MPage($this->onlineUserId, $this->onlineEnterpriseId, $this->areaCode); $dbResult = $objMPage->home(); if (!$dbResult->isSuccess()) { return ResultWrapper::fail($dbResult->getData(), ErrorCode::$dberror); } $allModuleData = $dbResult->getData(); break; } $allModuleData = array_values($allModuleData); $return = [ 'data' => $allModuleData, ]; return ResultWrapper::success($return); } /** * @return ResultWrapper * @throws \Exception */ public function homePage($pageType = 1,$shopId = null) { //根据企业id查找模板id $templateId = $this->objDEnterpriseBindTemplate->get_field('templateId', ['enterpriseId' => $this->onlineEnterpriseId, 'enableStatus' => StatusCode::$standard]); if ($templateId === false) { return ResultWrapper::fail($this->objDEnterpriseBindTemplate->error(), ErrorCode::$dberror); } if (empty($templateId)) { $templateId = 3; // 如果企业没设置模板,默认使用万能模板 //return ResultWrapper::fail('当前企业没有正在使用的模版', ErrorCode::$dberror); } //根据模板id查找模板类型 $type = $this->objDSystemTemplate->get_field('type', ['id' => $templateId]); if ($type === false) { return ResultWrapper::fail($this->objDSystemTemplate->error(), ErrorCode::$dberror); } // if (empty($type)) { // return ResultWrapper::fail('获取模版失败', ErrorCode::$contentNotExists); // } $allModuleData = []; if (!$type) $type = 2; switch ($type) { case StatusCode::$templateType['ordinary']: //普通模版 //获取该模版平台设置的模块 $objDTemplateModule = new DTemplateModule(); $module = $objDTemplateModule->select(['templateId' => $templateId, 'enableStatus' => StatusCode::$standard]); if ($module === false) { return ResultWrapper::fail($objDTemplateModule->error(), ErrorCode::$dberror); } //获取该企业下显示的模块,模块下的数据 $objMEnterpriseTemplateModule = new MEnterpriseTemplateModule($this->onlineUserId, $this->onlineEnterpriseId); $moduleData = $objMEnterpriseTemplateModule->getModuleByIds(['templateId' => $templateId, 'moduleId' => array_column($module, 'id')]); //验证商品有效性 $moduleData = self::checkModule($moduleData); foreach ($module as $key => $val) { $allModuleData[$val['alias']] = [ 'moduleAlias' => $val['alias'], 'enableStatus' => isset($moduleData[$val['alias']]['enableStatus']) ? $moduleData[$val['alias']]['enableStatus'] : StatusCode::$standard, 'moduleData' => isset($moduleData[$val['alias']]['moduleData']) ? json_decode($moduleData[$val['alias']]['moduleData'], true) : [], ]; } break; case StatusCode::$templateType['universal']: //万能模版 $objMPage = new MPage($this->onlineUserId, $this->onlineEnterpriseId, $this->areaCode); // 获取app首页 $dbResult = $objMPage->home($pageType,$shopId); if (!$dbResult->isSuccess()) { return ResultWrapper::fail($dbResult->getData(), ErrorCode::$dberror); } $allModuleData = $dbResult->getData(); break; } $allModuleData = array_values($allModuleData); $all['type'] = $type; $all['data'] = $allModuleData; $return = [ 'data' => $all, ]; return ResultWrapper::success($return); } /** * 检测模块数据中的下架和删除数据 isInvalid=>4(已失效) isInvalid=>5(正常) * @param $data * @return mixed */ private function checkModule($data) { if (empty($data)) return $data; //热销商品模块 if (isset($data['hotGoods'])) { $hotGoods = empty($data['hotGoods']['moduleData']) ? [] : json_decode($data['hotGoods']['moduleData'], true); $goodsData = $hotGoods['goodsData']; $goodsId = array_unique(array_column($goodsData, 'id')); $objMGoods = new MGoods($this->onlineEnterpriseId, false, $this->onlineUserId); $pageParams = pageToOffset(1, 10); $selectParams = [ 'goodsIds' => array_values($goodsId), 'limit' => $pageParams['limit'], 'offset' => $pageParams['offset'], 'userCenterId' => $this->onlineUserId, ]; // 搜索商品 $result = $objMGoods->search($selectParams); if (!$result->isSuccess()) { return $data; } $goodsData = $result->getData()['data']; foreach ($goodsData as $key => $val) { foreach ($val['skuData'] as $sku) { if ($sku['isMaster'] == StatusCode::$standard) { $goodsData[$key]['salePrice'] = $sku['salePrice']; $goodsData[$key]['inventory'] = $sku['inventory']; $goodsData[$key]['unitName'] = $sku['unitName']; } } } //$objMGoods->getGoodsNames($goodsId); foreach ($goodsData as $key => &$val) { $val['isInvalid'] = StatusCode::$standard; } $hotGoods['goodsData'] = $goodsData; $data['hotGoods']['moduleData'] = json_encode($hotGoods); unset($val); unset($goodsId); unset($result); } //首页商品分类模块 if (isset($data['goodsCate'])) { $goodsCate = json_decode($data['goodsCate']['moduleData'], true); $cateData = $goodsCate['cateData']; $goodsId = []; foreach ($cateData as $key => $val) { foreach ($val['goodsData'] as $goods) { $goodsId[] = $goods['id']; } } $objMGoods = new MGoods($this->onlineEnterpriseId, false, $this->onlineUserId); $pageParams = pageToOffset(1, 100); $selectParams = [ 'goodsIds' => array_values(array_unique($goodsId)), 'limit' => $pageParams['limit'], 'offset' => $pageParams['offset'], 'userCenterId' => $this->onlineUserId, ]; $result = $objMGoods->search($selectParams); if (!$result->isSuccess()) { return $data; } $goodsData = $result->getData()['data']; $allGoodsData = []; foreach ($goodsData as $key => &$val) { foreach ($val['skuData'] as $sku) { if ($sku['isMaster'] == StatusCode::$standard) { $goodsData[$key]['salePrice'] = $sku['salePrice']; $goodsData[$key]['inventory'] = $sku['inventory']; $goodsData[$key]['unitName'] = $sku['unitName']; } } $allGoodsData[$val['id']] = $val; } //$result = $objMGoods->getGoodsNames(array_unique($goodsId)); foreach ($cateData as $key => &$val) { $newGoods = []; foreach ($val['goodsData'] as &$goods) { if (isset($allGoodsData[$goods['id']])) { $newGoods[] = $allGoodsData[$goods['id']]; } } $val['goodsData'] = $newGoods; } $goodsCate['cateData'] = $cateData; $data['goodsCate']['moduleData'] = json_encode($goodsCate); } return $data; } /** * 更新审核状态及信息 * @param $callback * @param $params * @return ResultWrapper */ public function getAuditStatus($params) { $oplatformConfigData = Factory::config()->getAppoint('weixin', 'oplatform'); if (empty($oplatformConfigData)) { return ResultWrapper::fail('微信三方平台配置错误', ErrorCode::$paramError); } // 获取当前登录企业的小程序配置 $objSystemCache = new SystemCache(); $miniprogramSetting = $objSystemCache->getAppIdByEnterpriseId($this->onlineEnterpriseId); if (empty($miniprogramSetting)) { return ResultWrapper::fail('后台小程序配置项为空', ErrorCode::$configEroor); } $miniprogramSetting = json_decode($miniprogramSetting, true); // 企业设置的小程序id $authorizer_appid = $miniprogramSetting['appid']; $objOplatform = new Oplatform($oplatformConfigData['appid'], $oplatformConfigData['token'], $oplatformConfigData['encodingAesKey'], $oplatformConfigData['appSecret']); $result = $objOplatform->getAuditstatus($authorizer_appid, $params['auditId']);//TODO if (!$result->isSuccess()) { return ResultWrapper::fail($result->getData(), ErrorCode::$dberror); } $callback = $result->getData(); if ($callback['status'] == StatusCode::$wxAuditStatus['refuse']) { $reason = [ 'reason' => isset($callback['reason']) ? $callback['reason'] : '', 'ScreenShot' => isset($callback['ScreenShot']) ? $callback['ScreenShot'] : '', ]; } $dbResult = $this->objDEnterpriseBindTemplate->update([ 'auditStatus' => isset($callback['status']) ? $callback['status'] : StatusCode::$wxAuditStatus['inAudit'], 'reason' => isset($reason) ? json_encode($reason) : '[]', ], [ 'templateId' => $params['templateId'], 'enterpriseId' => $this->onlineEnterpriseId, ]); if ($dbResult === false) { return ResultWrapper::fail($this->objDEnterpriseBindTemplate->error(), ErrorCode::$dberror); } switch (isset($callback['status']) ? $callback['status'] : '') { case 0: $message = '审核成功'; break; case 1: $message = '审核被拒绝'; break; case 2: $message = '审核中'; break; case 3: $message = '已撤回'; break; case 4: $message = '审核延后'; break; default: $message = '未查询到'; break; } $return = [ 'message' => $message, 'reason' => isset($reason) ? $reason : [] ]; return ResultWrapper::success($return); } /** * 回调修改模版审核状态 * @param $params * @return bool */ public function updateAuditStatus($params) { $objDWxBindEnterprise = new DWxBindEnterprise(); $dbResult = $objDWxBindEnterprise->get_field('enterpriseId', ['wxOriginId' => $params['ToUserName']]); if ($dbResult === false) { return false; } $dbResult = $this->objDEnterpriseBindTemplate->update( [ 'auditStatus' => $params['auditStatus'], 'reason' => isset($params['reason']) ? json_encode($params['reason']) : '[]', ], ['enterpriseId' => $dbResult, 'enableStatus' => StatusCode::$standard] ); if ($dbResult === false) { return false; } return true; } /**********************************************重写 start**********************************************************/ /** * 1.提交代码 * * @param $params * @param $token * @return ResultWrapper */ public function submitCode($params, $token) { // 启用得微信模板id $weixinTemplateId = $params['weixinTemplateId']; unset($params['weixinTemplateId']); // 获取当前登录企业的小程序配置 $objSystemCache = new SystemCache(); $miniprogramSetting = $objSystemCache->getAppIdByEnterpriseId($this->onlineEnterpriseId); if (empty($miniprogramSetting)) { return ResultWrapper::fail('后台小程序配置项为空', ErrorCode::$configEroor); } $miniprogramSetting = json_decode($miniprogramSetting, true); // 企业设置的小程序id $authorizer_appid = $miniprogramSetting['appid']; /* $oplatformConfigData = Factory::config()->getAppoint('weixin', 'oplatform'); if (empty($oplatformConfigData)) { return ResultWrapper::fail('配置错误', ErrorCode::$paramError); }*/ // 获取微信开放平台配置 $objMOem = new MOem(); // 默认作为SAAS用户后台操作方式获取配置 $refererUrl = parse_url($_SERVER['HTTP_REFERER']); $host = $refererUrl['host']; $result = $objMOem->getOemInfoByDomain($host); if( !$result->isSuccess() ){ return ResultWrapper::fail($result->getData(), $result->getErrorCode()); } $oemData = $result->getData(); // 如果用企业id说明管理后台操作 if(isset($params['enterpriseId']) && !empty($params['enterpriseId']) && empty($oemData)){ // 先拿传过来的企业查询去查询 $result = $objMOem->getOemInfoByenterpriseId($params['enterpriseId']); if( !$result->isSuccess() ){ return ResultWrapper::fail($result->getData(), $result->getErrorCode()); } $oemData = $result->getData(); // 如果为空,用默认平台企业去操作 if(empty($oemData)){ $result = $objMOem->getOemInfoByenterpriseId(4); if( !$result->isSuccess() ){ return ResultWrapper::fail($result->getData(), $result->getErrorCode()); } $oemData = $result->getData(); } } if( empty($oemData) ){ return ResultWrapper::fail('oem表中获取配置为空', ErrorCode::$contentNotExists); } $oplatformConfigData = json_decode($oemData['weixinOpen'], true); if( empty($oplatformConfigData) ){ return ResultWrapper::fail('oem表中获取微信开放平台配置为空', ErrorCode::$contentNotExists); } $objOplatform = new Oplatform($oplatformConfigData['appid'], $oplatformConfigData['token'], $oplatformConfigData['encodingAesKey'], $oplatformConfigData['appSecret']); //设置服务器域名 if( empty($oemData['apiDomain']) ){ return ResultWrapper::fail('oem表中获取api接口域名配置为空', ErrorCode::$contentNotExists); } $setResult = $objOplatform->modifyDomain($authorizer_appid, $oemData['apiDomain']); if (!$setResult->isSuccess()){ return ResultWrapper::fail($setResult->getData(), $setResult->getErrorCode()); } $accountResult = $accountResult = $objOplatform->apiGetAuthorizerInfo($authorizer_appid); if (!$accountResult->isSuccess()){ return ResultWrapper::fail($accountResult->getData(),$accountResult->getErrorCode()); } $account = $accountResult->getData(); //个人类型小程序不能设置业务域名 if (isset($account['authorizer_info']['principal_name']) && $account['authorizer_info']['principal_name'] != '个人'){ $setResult = $objOplatform->setwebviewdomain($authorizer_appid, $oemData['apiDomain']); if (!$setResult->isSuccess()){ return ResultWrapper::fail($setResult->getData(), $setResult->getErrorCode()); } } $ext_json = [ 'extEnable' => 'true', 'extAppid' => $miniprogramSetting['appid'], 'directCommit' => false, 'ext' => [ 'token' => $token, ], ]; // 代理的从数据库表中获取模板id if( empty($oemData['weixinTemplateId']) ){ return ResultWrapper::fail('oem表中获取微信开发平台模板id配置为空', ErrorCode::$contentNotExists); } $weixinTemplateId = $oemData['weixinTemplateId']; // 1.上传小程序 $result = $objOplatform->commit($authorizer_appid, $weixinTemplateId, $ext_json, '1.0', '切换模板'); if (!$result->isSuccess()) { return ResultWrapper::fail($result->getData(), $result->getErrorCode()); } // 2.获取已上传的代码的页面列表 unset($result); $result = $objOplatform->getPage($authorizer_appid); if (!$result->isSuccess()) { return ResultWrapper::fail($result->getData(), $result->getErrorCode()); } $pageList = $result->getData(); // 3.获取的体验版二维码 unset($result); $result = $objOplatform->getQrcode($authorizer_appid, $pageList[0]); if (!$result->isSuccess()) { return ResultWrapper::fail($result->getData(), $result->getErrorCode()); } if (!is_dir(UPLOAD_FILE_PATH)) { mkdir(UPLOAD_FILE_PATH, 0777, true); } if (!file_put_contents(UPLOAD_FILE_PATH . $authorizer_appid . '.jpeg', $result->getData())) { return ResultWrapper::fail('保存体验二维码失败', ErrorCode::$contentNotExists); } //关闭其他所有开启的模版 $dbResult = $this->objDEnterpriseBindTemplate->update(['enableStatus' => StatusCode::$delete, 'status' => StatusCode::$delete], ['enterpriseId' => $this->onlineEnterpriseId, 'enableStatus' => StatusCode::$standard]); if ($dbResult === false) { return ResultWrapper::fail($this->objDEnterpriseBindTemplate->error(), ErrorCode::$dberror); } $params['auditStatus'] = StatusCode::$wxAuditStatus['noSubmit'];//代码提交成功,可以点击审核 $params['qrcodeImg'] = URL_UPLOAD . $authorizer_appid . '.jpeg';//二维码地址 $params['status'] = StatusCode::$standard;//已提交代码 $dbResult = $this->objDEnterpriseBindTemplate->replace($params); if ($dbResult === false) { return ResultWrapper::fail($this->objDEnterpriseBindTemplate->error(), ErrorCode::$dberror); } return ResultWrapper::success('上传代码成功'); } /** * 2.提交审核 * * @param $params * @return ResultWrapper */ public function submitAudit($params) { // 获取当前登录企业的小程序配置 $objSystemCache = new SystemCache(); $miniprogramSetting = $objSystemCache->getAppIdByEnterpriseId($this->onlineEnterpriseId); if (empty($miniprogramSetting)) { return ResultWrapper::fail('后台小程序配置项为空', ErrorCode::$configEroor); } $miniprogramSetting = json_decode($miniprogramSetting, true); // 企业设置的小程序id $authorizer_appid = $miniprogramSetting['appid']; /* $oplatformConfigData = Factory::config()->getAppoint('weixin', 'oplatform'); if (empty($oplatformConfigData)) { return ResultWrapper::fail('微信三方平台配置错误', ErrorCode::$paramError); }*/ // 如果用企业id说明管理后台操作 如果没有说明客户自己SAAS系统后台操作 获取微信开放平台配置 $objMOem = new MOem(); if(isset($params['enterpriseId']) && !empty($params['enterpriseId'])){ // 先拿传过来的企业查询去查询 $result = $objMOem->getOemInfoByenterpriseId($params['enterpriseId']); if( !$result->isSuccess() ){ return ResultWrapper::fail($result->getData(), $result->getErrorCode()); } $oemData = $result->getData(); // 如果为空,用默认平台企业去操作 if(empty($oemData)){ $result = $objMOem->getOemInfoByenterpriseId(4); if( !$result->isSuccess() ){ return ResultWrapper::fail($result->getData(), $result->getErrorCode()); } $oemData = $result->getData(); } }else{ $refererUrl = parse_url($_SERVER['HTTP_REFERER']); $host = $refererUrl['host']; $result = $objMOem->getOemInfoByDomain($host); if( !$result->isSuccess() ){ return ResultWrapper::fail($result->getData(), $result->getErrorCode()); } $oemData = $result->getData(); } if( empty($oemData) ){ return ResultWrapper::fail('oem表中获取配置为空', ErrorCode::$contentNotExists); } $oplatformConfigData = json_decode($oemData['weixinOpen'], true); if( empty($oplatformConfigData) ){ return ResultWrapper::fail('oem表中获取微信开放平台配置为空', ErrorCode::$contentNotExists); } $objOplatform = new Oplatform($oplatformConfigData['appid'], $oplatformConfigData['token'], $oplatformConfigData['encodingAesKey'], $oplatformConfigData['appSecret']); $result = $objOplatform->submitAudit($authorizer_appid); if (!$result->isSuccess()) { return ResultWrapper::fail($result->getData(), ErrorCode::$dberror); } $callback = $result->getData(); $dbResult = $this->objDEnterpriseBindTemplate->update([ 'auditId' => is_numeric($callback) ? $callback : '', 'auditStatus' => StatusCode::$wxAuditStatus['inAudit'],//提交审核成功,进入审核中 ], [ 'templateId' => $params['templateId'], 'enterpriseId' => $this->onlineEnterpriseId, ]); if ($dbResult === false) { return ResultWrapper::fail($this->objDEnterpriseBindTemplate->error(), ErrorCode::$dberror); } return ResultWrapper::success($dbResult); } /** * 3.发布 * * @param $params * @return ResultWrapper */ public function release($params) { /*$oplatformConfigData = Factory::config()->getAppoint('weixin', 'oplatform'); if (empty($oplatformConfigData)) { return ResultWrapper::fail('微信三方平台配置错误', ErrorCode::$paramError); }*/ // 获取微信开放平台配置 $objMOem = new MOem(); // 如果用企业id说明管理后台操作 如果没有说明客户自己SAAS系统后台操作 if(isset($params['enterpriseId']) && !empty($params['enterpriseId'])){ // 先拿传过来的企业查询去查询 $result = $objMOem->getOemInfoByenterpriseId($params['enterpriseId']); if( !$result->isSuccess() ){ return ResultWrapper::fail($result->getData(), $result->getErrorCode()); } $oemData = $result->getData(); // 如果为空,用默认平台企业去操作 if(empty($oemData)){ $result = $objMOem->getOemInfoByenterpriseId(4); if( !$result->isSuccess() ){ return ResultWrapper::fail($result->getData(), $result->getErrorCode()); } $oemData = $result->getData(); } }else{ $refererUrl = parse_url($_SERVER['HTTP_REFERER']); $host = $refererUrl['host']; $result = $objMOem->getOemInfoByDomain($host); if( !$result->isSuccess() ){ return ResultWrapper::fail($result->getData(), $result->getErrorCode()); } $oemData = $result->getData(); } if( empty($oemData) ){ return ResultWrapper::fail('oem表中获取配置为空', ErrorCode::$contentNotExists); } $oplatformConfigData = json_decode($oemData['weixinOpen'], true); if( empty($oplatformConfigData) ){ return ResultWrapper::fail('oem表中获取微信开放平台配置为空', ErrorCode::$contentNotExists); } $objOplatform = new Oplatform($oplatformConfigData['appid'], $oplatformConfigData['token'], $oplatformConfigData['encodingAesKey'], $oplatformConfigData['appSecret']); // 获取当前登录企业的小程序配置 $objSystemCache = new SystemCache(); $miniprogramSetting = $objSystemCache->getAppIdByEnterpriseId($this->onlineEnterpriseId); if (empty($miniprogramSetting)) { return ResultWrapper::fail('后台小程序配置项为空', ErrorCode::$configEroor); } $miniprogramSetting = json_decode($miniprogramSetting, true); $result = $objOplatform->release($miniprogramSetting['appid']); if (!$result->isSuccess()) { return ResultWrapper::fail($result->getData(), ErrorCode::$dberror); } //修改模版启用状态 $dbResult = $this->objDEnterpriseBindTemplate->update([ 'auditStatus' => StatusCode::$wxAuditStatus['beingUsed'],//审核成功,发布小程序成功进入正在使用状态 ], [ 'templateId' => $params['templateId'], 'enterpriseId' => $this->onlineEnterpriseId, ]); if ($dbResult === false) { return ResultWrapper::fail($this->objDEnterpriseBindTemplate->error(), ErrorCode::$dberror); } return ResultWrapper::success($result->getData()); } /** * 审核撤回 * @param $params * @return ResultWrapper */ public function revoke($params) { /* $oplatformConfigData = Factory::config()->getAppoint('weixin', 'oplatform'); if (empty($oplatformConfigData)) { return ResultWrapper::fail('微信三方平台配置错误', ErrorCode::$paramError); }*/ // 如果用企业id说明管理后台操作 如果没有说明客户自己SAAS系统后台操作 获取微信开放平台配置 $objMOem = new MOem(); if(isset($params['enterpriseId']) && !empty($params['enterpriseId'])){ // 先拿传过来的企业查询去查询 $result = $objMOem->getOemInfoByenterpriseId($params['enterpriseId']); if( !$result->isSuccess() ){ return ResultWrapper::fail($result->getData(), $result->getErrorCode()); } $oemData = $result->getData(); // 如果为空,用默认平台企业去操作 if(empty($oemData)){ $result = $objMOem->getOemInfoByenterpriseId(4); if( !$result->isSuccess() ){ return ResultWrapper::fail($result->getData(), $result->getErrorCode()); } $oemData = $result->getData(); } }else{ $refererUrl = parse_url($_SERVER['HTTP_REFERER']); $host = $refererUrl['host']; $result = $objMOem->getOemInfoByDomain($host); if( !$result->isSuccess() ){ return ResultWrapper::fail($result->getData(), $result->getErrorCode()); } $oemData = $result->getData(); } if( empty($oemData) ){ return ResultWrapper::fail('oem表中获取配置为空', ErrorCode::$contentNotExists); } $oplatformConfigData = json_decode($oemData['weixinOpen'], true); if( empty($oplatformConfigData) ){ return ResultWrapper::fail('oem表中获取微信开放平台配置为空', ErrorCode::$contentNotExists); } $objOplatform = new Oplatform($oplatformConfigData['appid'], $oplatformConfigData['token'], $oplatformConfigData['encodingAesKey'], $oplatformConfigData['appSecret']); // 获取当前登录企业的小程序配置 $objSystemCache = new SystemCache(); $miniprogramSetting = $objSystemCache->getAppIdByEnterpriseId($this->onlineEnterpriseId); if (empty($miniprogramSetting)) { return ResultWrapper::fail('后台小程序配置项为空', ErrorCode::$configEroor); } $miniprogramSetting = json_decode($miniprogramSetting, true); $result = $objOplatform->undocodeaudit($miniprogramSetting['appid']); if (!$result->isSuccess()) { return ResultWrapper::fail($result->getData(), $result->getErrorCode()); } //修改状态 $dbResult = $this->objDEnterpriseBindTemplate->update([ 'auditStatus' => StatusCode::$wxAuditStatus['beenRelease'],//撤回成功,初始状态 ], [ 'templateId' => $params['templateId'], 'enterpriseId' => $this->onlineEnterpriseId, ]); if ($dbResult === false) { return ResultWrapper::fail($this->objDEnterpriseBindTemplate->error(), ErrorCode::$dberror); } return ResultWrapper::success($result->getData()); } /** * 获取提交代码后小程序的状态 * * @return ResultWrapper */ public function getWxStatus() { $dbResult = $this->objDEnterpriseBindTemplate->get( [ 'enterpriseId' => $this->onlineEnterpriseId, 'status' => StatusCode::$standard ], 'id,templateId,auditStatus' ); if (empty($dbResult)) { $dbResult = [ 'id' => null, 'templateId' => null, 'status' => null, ]; } return ResultWrapper::success($dbResult); } }