get('site');
$site = json_decode($site,true);
self::$theme = $site['theme']??'qt';
self::$appId = $site['mini_appid'] ?? 'wx5413e3ee18d63891';
self::$secret = $site['mini_secret'] ?? '3f90edade24ecbff6353e9ba9d175049';
}
/**
* 生成发送的小程序内容
* @param $item
* @param $channelId
* @return string
*/
public function getMiniProgram($mini,$channelId)
{
$channelId = self::$theme.'_'.$channelId;
if ( !isset($mini['type']) || !$mini['type']){
return '';
}
$content = $mini;
$content['page'] = trim($content['page']);
$t = '';
switch ($content['type']){
case 1:
$content['page'] .= '?channelCode='.$channelId;
$t = self::getMiniText($content['page'],$content['content']);
break;
case 2:
$content['page'] .= '?channelCode='.$channelId;
$t = self::getMiniImg($content['page'],$content['pic']);
// print_r($t);exit;
break;
case 3:
$content['page'] .= '?channelCode='.$channelId;
$t = self::getMiniCard($content['page'],$content['title'],$content['pic']);
break;
case 4:
$scene = '@channelCode='.$channelId;
$t = self::getAppCode($scene,$content['page'],$channelId);
break;
default:
break;
}
return $t;
}
public static function getAppCode($scene,$page,$channelId, $cache = false)
{
$redisKey = 'MINI:'.$channelId.$page;
if($cache){
$url = Redis::instance()->get($redisKey);
if (!empty($url)){
return $url;
}
}
$app = self::initMiniProgram();
$path = '/uploads/wcode/'.date('Ymd').'/';
$picPath = ROOT_PATH.'public/'.$path;
$page = trim($page,'/');
$picFileName = time().$channelId.rand(1000,9999).'.png';
try{
$response = $app->app_code->getUnlimit($scene,['page'=>$page]);
if ($response instanceof \EasyWeChat\Kernel\Http\StreamResponse) {
$response->saveAs($picPath, $picFileName);
} else {
$msg = var_export($response, true);
LogService::info('高级群发生成小程序码异常01'.$msg);
}
}catch (\Throwable $th){
LogService::error('高级群发生成小程序码异常02'.$th->getMessage());
return '';
}
if ($cache){
Redis::instance()->setex($redisKey,86400,$path.$picFileName);
}
return $path.$picFileName;
}
/**
* 小程序卡片
* @param $appId
* @param $page
* @param $title
* @param $pic
* @return string
*/
public static function getMiniCard($page,$title,$pic){
$str = '