修改微信模块

This commit is contained in:
Anyon 2019-12-09 18:51:25 +08:00
parent 37bc7f8a96
commit 951f9d1dbf
4 changed files with 25 additions and 33 deletions

View File

@ -39,11 +39,11 @@ class Js extends Controller
public function index()
{
$url = $this->request->server('http_referer', $this->request->url(true));
$wechat = WechatService::instance()->getWebOauthInfo($url, $this->request->get('mode', 1), false);
$openid = isset($wechat['openid']) ? $wechat['openid'] : '';
$unionid = empty($wechat['fansinfo']['unionid']) ? '' : $wechat['fansinfo']['unionid'];
$user = WechatService::instance()->getWebOauthInfo($url, $this->request->get('mode', 1), false);
$openid = isset($user['openid']) ? $user['openid'] : '';
$unionid = empty($user['fansinfo']['unionid']) ? '' : $user['fansinfo']['unionid'];
$configJson = json_encode(WechatService::instance()->getWebJssdkSign($url), JSON_UNESCAPED_UNICODE);
$fansinfoJson = json_encode(isset($wechat['fansinfo']) ? $wechat['fansinfo'] : [], JSON_UNESCAPED_UNICODE);
$fansinfoJson = json_encode(isset($user['fansinfo']) ? $user['fansinfo'] : [], JSON_UNESCAPED_UNICODE);
$html = <<<EOF
if(typeof wx === 'object'){
wx.openid="{$openid}";

View File

@ -145,6 +145,7 @@ class Push extends Controller
* @throws \WeChat\Exceptions\LocalCacheException
* @throws \think\Exception
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
protected function text()
@ -202,9 +203,8 @@ class Push extends Controller
* @throws \WeChat\Exceptions\LocalCacheException
* @throws \think\Exception
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
* @throws \think\exception\PDOException
*/
private function keys($rule, $isLast = false, $isCustom = false)
{
@ -222,30 +222,30 @@ class Push extends Controller
case 'customservice':
return $this->sendMessage('customservice', ['content' => $data['content']], false);
case 'voice':
if (empty($data['voice_url']) || !($mediaId = MediaService::upload($data['voice_url'], 'voice'))) return false;
if (empty($data['voice_url']) || !($mediaId = MediaService::instance()->upload($data['voice_url'], 'voice'))) return false;
return $this->sendMessage('voice', ['media_id' => $mediaId], $isCustom);
case 'image':
if (empty($data['image_url']) || !($mediaId = MediaService::upload($data['image_url'], 'image'))) return false;
if (empty($data['image_url']) || !($mediaId = MediaService::instance()->upload($data['image_url'], 'image'))) return false;
return $this->sendMessage('image', ['media_id' => $mediaId], $isCustom);
case 'news':
list($news, $articles) = [MediaService::news($data['news_id']), []];
list($news, $articles) = [MediaService::instance()->news($data['news_id']), []];
if (empty($news['articles'])) return false;
foreach ($news['articles'] as $vo) array_push($articles, [
'url' => url("@wechat/api.review/view", '', false, true) . "?id={$vo['id']}",
'url' => url("@wechat/api.review/view", [], false, true) . "?id={$vo['id']}",
'title' => $vo['title'], 'picurl' => $vo['local_url'], 'description' => $vo['digest'],
]);
return $this->sendMessage('news', ['articles' => $articles], $isCustom);
case 'music':
if (empty($data['music_url']) || empty($data['music_title']) || empty($data['music_desc'])) return false;
return $this->sendMessage('music', [
'thumb_media_id' => empty($data['music_image']) ? '' : MediaService::upload($data['music_image'], 'image'),
'thumb_media_id' => empty($data['music_image']) ? '' : MediaService::instance()->upload($data['music_image'], 'image'),
'description' => $data['music_desc'], 'title' => $data['music_title'],
'hqmusicurl' => $data['music_url'], 'musicurl' => $data['music_url'],
], $isCustom);
case 'video':
if (empty($data['video_url']) || empty($data['video_desc']) || empty($data['video_title'])) return false;
$videoData = ['title' => $data['video_title'], 'introduction' => $data['video_desc']];
if (!($mediaId = MediaService::upload($data['video_url'], 'video', $videoData))) return false;
if (!($mediaId = MediaService::instance()->upload($data['video_url'], 'video', $videoData))) return false;
return $this->sendMessage('video', ['media_id' => $mediaId, 'title' => $data['video_title'], 'description' => $data['video_desc']], $isCustom);
default:
return false;
@ -261,8 +261,6 @@ class Push extends Controller
* @throws \WeChat\Exceptions\InvalidDecryptException
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
* @throws \think\Exception
* @throws \think\exception\PDOException
*/
private function sendMessage($type, $data, $isCustom = false)
{

View File

@ -5,7 +5,7 @@
<div class="layui-form-item layui-inline">
<label class="layui-form-label">微信昵称</label>
<div class="layui-input-inline">
<input name="nickname" value="{$Think.get.nickname|default=''}" placeholder="请输入微信昵称" class="layui-input">
<input name="nickname" value="{:input('nickname')}" placeholder="请输入微信昵称" class="layui-input">
</div>
</div>
@ -14,11 +14,11 @@
<div class="layui-input-inline">
<select class="layui-select" name="subscribe">
{foreach [''=>'-- 全部 --','0'=>'显示未关注的粉丝','1'=>'显示已关注的粉丝'] as $k=>$v}
{eq name='Think.get.subscribe' value='$k.""'}
{if $k.'' eq input('subscribe')}
<option selected value="{$k}">{$v}</option>
{else}
<option value="{$k}">{$v}</option>
{/eq}
{/if}
{/foreach}
</select>
</div>
@ -29,11 +29,11 @@
<div class="layui-input-inline">
<select class="layui-select" name="is_black">
{foreach [''=>'-- 全部 --','0'=>'显示未拉黑的粉丝','1'=>'显示已拉黑的粉丝'] as $k=>$v}
{eq name='Think.get.is_black' value='$k.""'}
{if $k.'' eq input('is_black')}
<option selected value="{$k}">{$v}</option>
{else}
<option value="{$k}">{$v}</option>
{/eq}
{/if}
{/foreach}
</select>
</div>
@ -42,7 +42,7 @@
<div class="layui-form-item layui-inline">
<label class="layui-form-label">关注时间</label>
<div class="layui-input-inline">
<input name="subscribe_at" value="{$Think.get.subscribe_at|default=''}" placeholder="请选择关注时间" class="layui-input">
<input data-date-range name="subscribe_at" value="{:input('subscribe_at')}" placeholder="请选择关注时间" class="layui-input">
</div>
</div>
@ -53,7 +53,4 @@
</fieldset>
<script>
window.form.render();
window.laydate.render({range: true, elem: '[name="subscribe_at"]'});
</script>
<script>window.form.render()</script>

View File

@ -13,11 +13,11 @@
<select class="layui-select" name="type">
<option value="">-- 全部 --</option>
{foreach $types as $k=>$v}
{eq name='Think.get.type' value='$k.""'}
{if $k.'' eq input('type')}
<option selected value="{$k}">{$v}</option>
{else}
<option value="{$k}">{$v}</option>
{/eq}
{/if}
{/foreach}
</select>
</div>
@ -27,11 +27,11 @@
<div class="layui-input-inline">
<select class="layui-select" name="status">
{foreach [''=>'-- 全部 --','0'=>'显示使用的规则','1'=>'显示禁止的规则'] as $k=>$v}
{eq name='Think.get.status' value='$k.""'}
{if $k.'' eq input('status')}
<option selected value="{$k}">{$v}</option>
{else}
<option value="{$k}">{$v}</option>
{/eq}
{/if}
{/foreach}
</select>
</div>
@ -39,7 +39,7 @@
<div class="layui-form-item layui-inline">
<label class="layui-form-label">创建时间</label>
<div class="layui-input-inline">
<input name="create_at" value="{$Think.get.create_at|default=''}" placeholder="请选择创建时间" class="layui-input">
<input data-date-range name="create_at" value="{$Think.get.create_at|default=''}" placeholder="请选择创建时间" class="layui-input">
</div>
</div>
<div class="layui-form-item layui-inline">
@ -48,7 +48,4 @@
</form>
</fieldset>
<script>
window.form.render();
window.laydate.render({range: true, elem: '[name="create_at"]'});
</script>
<script>window.form.render()</script>