Browse Source

微信自定义菜单

master
ZLW-PC\Administrator 7 years ago
parent
commit
2f2d2cbd5d
  1. 169
      app/Common/WechatCallbackApi.php
  2. 76
      app/Common/WechatMenu.php
  3. 203
      app/Http/Controllers/Admin/WeixinMenuController.php
  4. 8
      app/Http/Controllers/Weixin/UserController.php
  5. 2
      app/Http/Model/Arctype.php
  6. 181
      app/Http/Model/WeixinMenu.php
  7. 79
      public/css/weixin/style.css
  8. 86
      resources/views/admin/WeixinMenu/add.blade.php
  9. 82
      resources/views/admin/WeixinMenu/edit.blade.php
  10. 32
      resources/views/admin/WeixinMenu/index.blade.php
  11. 31
      resources/views/weixin/goods/goodsDetail.blade.php
  12. 6
      resources/views/weixin/user/index.blade.php
  13. 8
      routes/web.php

169
app/Common/WechatCallbackApi.php

@ -0,0 +1,169 @@
<?php
namespace App\Common;
/**
* 微信自定义菜单-响应菜单点击事件
*/
class WechatCallbackApi
{
public function valid()
{
$echoStr = $_GET["echostr"];
if($this->checkSignature())
{
echo $echoStr;
exit;
}
}
private function checkSignature()
{
$signature = $_GET["signature"];
$timestamp = $_GET["timestamp"];
$nonce = $_GET["nonce"];
$token = TOKEN;
$tmpArr = array($token, $timestamp, $nonce);
sort($tmpArr);
$tmpStr = implode( $tmpArr );
$tmpStr = sha1( $tmpStr );
if( $tmpStr == $signature )
{
return true;
}
else
{
return false;
}
}
public function responseMsg()
{
$postStr = $GLOBALS["HTTP_RAW_POST_DATA"];
if (!empty($postStr))
{
$postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA);
$RX_TYPE = trim($postObj->MsgType);
switch ($RX_TYPE)
{
case "text":
$resultStr = $this->receiveText($postObj);
break;
case "event":
$resultStr = $this->receiveEvent($postObj);
break;
default:
$resultStr = "";
break;
}
echo $resultStr;
}
else
{
echo "";
exit;
}
}
private function receiveText($object)
{
$funcFlag = 0;
$contentStr = "你发送的内容为:".$object->Content;
$resultStr = $this->transmitText($object, $contentStr, $funcFlag);
return $resultStr;
}
private function receiveEvent($object)
{
$contentStr = "";
switch ($object->Event)
{
case "subscribe":
$contentStr = "欢迎洋洋博客";
case "unsubscribe":
break;
case "CLICK":
switch ($object->EventKey)
{
case "company":
$contentStr[] = array("Title" =>"公司简介",
"Description" =>"洋洋的博客",
"PicUrl" =>"http://discuz.comli.com/weixin/weather/icon/cartoon.jpg",
"Url" =>"weixin://addfriend/pondbaystudio");
break;
default:
$contentStr[] = array("Title" =>"默认菜单回复",
"Description" =>"您正在使用的是<span style="font-family: Arial, Helvetica, sans-serif;">洋洋的博客</span><span style="font-family: Arial, Helvetica, sans-serif;">", </span>
"PicUrl" =>"http://discuz.comli.com/weixin/weather/icon/cartoon.jpg",
"Url" =>"weixin://addfriend/pondbaystudio");
break;
}
break;
default:
break;
}
if (is_array($contentStr))
{
$resultStr = $this->transmitNews($object, $contentStr);
}
else
{
$resultStr = $this->transmitText($object, $contentStr);
}
return $resultStr;
}
private function transmitText($object, $content, $funcFlag = 0)
{
$textTpl = "<xml>
<ToUserName><![CDATA[%s]]></ToUserName>
<FromUserName><![CDATA[%s]]></FromUserName>
<CreateTime>%s</CreateTime>
<MsgType><![CDATA[text]]></MsgType>
<Content><![CDATA[%s]]></Content>
<FuncFlag>%d</FuncFlag>
</xml>";
$resultStr = sprintf($textTpl, $object->FromUserName, $object->ToUserName, time(), $content, $funcFlag);
return $resultStr;
}
private function transmitNews($object, $arr_item, $funcFlag = 0)
{
//首条标题28字,其他标题39字
if(!is_array($arr_item))
return;
$itemTpl = "<item>
<Title><![CDATA[%s]]></Title>
<Description><![CDATA[%s]]></Description>
<PicUrl><![CDATA[%s]]></PicUrl>
<Url><![CDATA[%s]]></Url>
</item>
";
$item_str = "";
foreach ($arr_item as $item)
$item_str .= sprintf($itemTpl, $item['Title'], $item['Description'], $item['PicUrl'], $item['Url']);
$newsTpl = "<xml>
<ToUserName><![CDATA[%s]]></ToUserName>
<FromUserName><![CDATA[%s]]></FromUserName>
<CreateTime>%s</CreateTime>
<MsgType><![CDATA[news]]></MsgType>
<Content><![CDATA[]]></Content>
<ArticleCount>%s</ArticleCount>
<Articles>
$item_str</Articles>
<FuncFlag>%s</FuncFlag>
</xml>";
$resultStr = sprintf($newsTpl, $object->FromUserName, $object->ToUserName, time(), count($arr_item), $funcFlag);
return $resultStr;
}
}

76
app/Common/WechatMenu.php

@ -0,0 +1,76 @@
<?php
namespace App\Common;
/**
* 微信自定义菜单
*/
class WechatMenu
{
//高级功能->开发者模式->获取
private $app_id;
private $app_secret;
private $access_token;
private $expires_in;
public function __construct($app_id, $app_secret)
{
$this->app_id = $app_id;
$this->app_secret = $app_secret;
$token = $this->get_access_token();
$this->access_token = $token['access_token'];
$this->expires_in = $token['expires_in'];
}
/**
* 获取授权access_token
*
*/
public function get_access_token()
{
$token_url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={$this->app_id}&secret={$this->app_secret}";
$token_data = $this->http($token_url);
return json_decode($token_data, true);
}
//获取关注者列表
public function get_user_list($next_openid = NULL)
{
$url = "https://api.weixin.qq.com/cgi-bin/user/get?access_token=".$this->access_token."&next_openid=".$next_openid;
$res = $this->http($url);
return json_decode($res, true);
}
/**
* 自定义菜单创建
*
* @param string $jsonmenu
*/
public function create_menu($jsonmenu)
{
$url = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=".$this->access_token;
return $this->http($url, $jsonmenu);
}
// cURL函数简单封装
public function http($url, $data = null)
{
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
if (!empty($data))
{
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
}
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($curl);
curl_close($curl);
return $output;
}
}

203
app/Http/Controllers/Admin/WeixinMenuController.php

@ -0,0 +1,203 @@
<?php
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Admin\CommonController;
use DB;
use App\Http\Model\WeixinMenu;
use App\Common\WechatMenu;
class WeixinMenuController extends CommonController
{
public function __construct()
{
parent::__construct();
}
public function index()
{
$catlist = WeixinMenu::getList(array('is_show'=>-1));
$data['catlist'] = $catlist;
return view('admin.WeixinMenu.index', $data);
}
public function add()
{
if(!empty($_GET["reid"]))
{
$id = $_GET["reid"];
if(preg_match('/[0-9]*/',$id)){}else{exit;}
if($id!=0)
{
$data['postone'] = object_to_array(DB::table("weixin_menu")->where('id', $id)->first(), 1);
}
$data['id'] = $id;
}
else
{
$data['id'] = 0;
}
return view('admin.WeixinMenu.add', $data);
}
public function doadd()
{
if(!empty($_POST["prid"])){if($_POST["prid"]=="top"){$_POST['pid']=0;}else{$_POST['pid'] = $_POST["prid"];}}//父级栏目id
$_POST['addtime'] = time();//添加时间
unset($_POST["prid"]);
unset($_POST["_token"]);
if(DB::table('weixin_menu')->insert(array_filter($_POST)))
{
success_jump('添加成功!');
}
else
{
error_jump('添加失败!请修改后重新添加');
}
}
public function edit()
{
$id = $_GET["id"];if(preg_match('/[0-9]*/',$id)){}else{exit;}
$data['id'] = $id;
$post = object_to_array(DB::table('weixin_menu')->where('id', $id)->first(), 1);
$reid = $post['pid'];
if($reid!=0){$data['postone'] = object_to_array(DB::table('weixin_menu')->where('id', $reid)->first());}
$data['post'] = $post;
return view('admin.WeixinMenu.edit', $data);
}
public function doedit()
{
if(!empty($_POST["id"])){$id = $_POST["id"];unset($_POST["id"]);}else {$id="";exit;}
$_POST['addtime'] = time(); //添加时间
unset($_POST["_token"]);
if(DB::table('weixin_menu')->where('id', $id)->update(array_filter($_POST)))
{
success_jump('修改成功!', route('admin_weixinmenu'));
}
else
{
error_jump('修改失败!请修改后重新添加');
}
}
public function del()
{
if(!empty($_REQUEST["id"])){$id = $_REQUEST["id"];}else{error_jump('删除失败!请重新提交');} //if(preg_match('/[0-9]*/',$id)){}else{exit;}
if(DB::table('weixin_menu')->where('pid', $id)->first())
{
error_jump('删除失败!请先删除子栏目');
}
else
{
if(DB::table('weixin_menu')->where('id', $id)->delete())
{
success_jump('删除成功');
}
else
{
error_jump('删除失败!请重新提交');
}
}
}
public function createmenu()
{
$catlist = WeixinMenu::getList(array('is_show'=>-1));
$wechat_menu = new WechatMenu(sysconfig('CMS_WX_APPID'),sysconfig('CMS_WX_APPSECRET'));
/* $menu = array(
'button'=>array();
); */
$jsonmenu = '
{
"button":[
{
"name":"篮球",
"sub_button":[
{
"type":"click",
"name":"nba",
"key":"V1001_NBA"
},
{
"type":"click",
"name":"cba",
"key":"V1001_CBA"
}
]
},
{
"name":"体育",
"sub_button":[
{
"type":"view",
"name":"url",
"url":"http://m.hao123.com/a/tianqi"
},
{
"type":"click",
"name":"排球",
"key":"V1001_PAIQIU"
},
{
"type":"click",
"name":"网球",
"key":"V1001_WANGQIU"
},
{
"type":"click",
"name":"乒乓球",
"key":"V1001_PPQ"
},
{
"type":"click",
"name":"台球",
"key":"V1001_TAIQIU"
}
]
},
{
"name":"新闻",
"sub_button":[
{
"type":"click",
"name":"国内新闻",
"key":"V1001_GNNEWS"
},
{
"type":"click",
"name":"国际新闻",
"key":"V1001_GJNEWS"
},
{
"type":"click",
"name":"地方新闻",
"key":"V1001_AREANEWS"
},
{
"type":"click",
"name":"家庭新闻",
"key":"V1001_HOMENEWS"
}
]
}
]
}';
$wechat_menu->create_menu($jsonmenu);
success_jump('修改菜单,生成后,不会立即显示,有24小时的缓存,除非你取消关注,然后重新关注!', route('admin_weixinmenu'),5);
}
}

8
app/Http/Controllers/Weixin/UserController.php

@ -435,6 +435,9 @@ class UserController extends CommonController
header('Location: '.route('weixin_user'));exit;
}
$return_url = '';
if(isset($_REQUEST['return_url']) && !empty($_REQUEST['return_url'])){$return_url = $_SESSION['weixin_history_back_url'] = $_REQUEST['return_url'];}
if($_SERVER['REQUEST_METHOD'] == 'POST')
{
if($_POST['user_name'] == '')
@ -458,6 +461,7 @@ class UserController extends CommonController
$_SESSION['weixin_user_info'] = $res['data'];
if($return_url != ''){header('Location: '.$return_url);exit;}
header('Location: '.route('weixin_user'));exit;
}
@ -473,6 +477,10 @@ class UserController extends CommonController
header('Location: '.route('weixin_user'));exit;
}
$return_url = '';
if(isset($_REQUEST['return_url']) && !empty($_REQUEST['return_url'])){$_SESSION['weixin_history_back_url'] = $_REQUEST['return_url'];}
if(isset($_REQUEST['parent_id']) && !empty($_REQUEST['parent_id'])){$_SESSION['weixin_user_parent_id'] = $_REQUEST['parent_id'];} //推荐人id存在session,首页入口也存了一次
return view('weixin.user.register');
}

2
app/Http/Model/Arctype.php

@ -131,4 +131,4 @@ class Arctype extends Model
return true;
}
}
}

181
app/Http/Model/WeixinMenu.php

@ -0,0 +1,181 @@
<?php
namespace App\Http\Model;
use App\Common\ReturnData;
/**
* 微信自定义菜单
* 1、自定义菜单最多包括3个一级菜单,每个一级菜单最多包含5个二级菜单。
* 2、一级菜单最多4个汉字,二级菜单最多7个汉字,多出来的部分将会以“...”代替。
* 3、创建自定义菜单后,菜单的刷新策略是,在用户进入公众号会话页或公众号profile页时,如果发现上一次拉取菜单的请求在5分钟以前,就会拉取一下菜单,如果菜单有更新,就会刷新客户端的菜单。测试时可以尝试取消关注公众账号后再次关注,则可以看到创建后的效果。
*/
class WeixinMenu extends BaseModel
{
protected $table = 'weixin_menu';
public $timestamps = false;
/**
* 不能被批量赋值的属性
*
* @var array
*/
protected $guarded = array();
const IS_SHOW = 0;
//获取列表
public static function getList(array $param)
{
extract($param); //参数:limit,offset
if(isset($is_show) && $is_show!=-1){$where['is_show'] = $is_show;} //-1表示获取所有
$where['pid'] = 0;
$list = self::where($where)->orderBy('listorder', 'asc')->get();
if($list)
{
foreach($list as $k=>$v)
{
$res[] = $v;
$child = self::where(array('pid'=>$list[$k]->id,'is_show'=>self::IS_SHOW))->orderBy('listorder', 'asc')->get();
if($child)
{
foreach($child as $key=>$value)
{
$res[] = $value;
}
}
}
}
else
{
return false;
}
return $res;
}
public static function getOne($where)
{
return self::where($where)->first();
}
public static function add(array $data)
{
if ($id = self::insertGetId($data))
{
return $id;
}
return false;
}
public static function modify($where, array $data)
{
if (self::where($where)->update($data) === false)
{
return false;
}
return true;
}
//删除一条记录
public static function remove($id)
{
if (!self::whereIn('id', explode(',', $id))->delete())
{
return false;
}
return true;
}
//删除一条记录
public static function getWeixinMenuJson()
{
$where['pid'] = 0;
$where['is_show'] = self::IS_SHOW;
$list = self::where($where)->orderBy('listorder', 'asc')->get();
$res='';
if($list)
{
foreach($list as $k=>$v)
{
$child = self::where(array('pid'=>$list[$k]->id,'is_show'=>self::IS_SHOW))->orderBy('listorder', 'asc')->get();
if($child)
{
$temp_child='';
foreach($child as $key=>$value)
{
if($value->type == 'click')
{
$temp_child[] = array(
'type'=>$value->type,
'name'=>$value->name,
'key'=>$value->key
);
}
elseif($value->type == 'view')
{
$temp_child[] = array(
'type'=>$value->type,
'name'=>$value->name,
'url'=>$value->key
);
}
elseif($value->type == 'miniprogram')
{
$temp_child[] = array(
'type'=>$value->type,
'name'=>$value->name,
'url'=>$value->key,
'appid'=>$value->appid,
'pagepath'=>$value->pagepath
);
}
}
$res[] = array(
'name'=>$value->name,
'sub_button'=>$temp_child
);
}
else
{
if($v->type == 'click')
{
$res[] = array(
'type'=>$v->type,
'name'=>$v->name,
'key'=>$v->key
);
}
elseif($v->type == 'view')
{
$res[] = array(
'type'=>$v->type,
'name'=>$v->name,
'url'=>$v->key
);
}
elseif($v->type == 'miniprogram')
{
$res[] = array(
'type'=>$v->type,
'name'=>$v->name,
'url'=>$v->key,
'appid'=>$v->appid,
'pagepath'=>$v->pagepath
);
}
}
}
}
return json_encode($res);
}
}

79
public/css/weixin/style.css

@ -81,73 +81,18 @@ background:none;
.goods_list_s .goods_des{color:#999999;font-size:0.875rem;}
.goods_list_s .buy{border:1px solid #f23030;border-radius:2px;padding:0 3px;color:#fff;background-color:#f23030;}
.classreturn{
background-color:#f8f8f8;
border-bottom:1px solid #dedede;
position:relative;
text-align:center;
line-height:50px;
padding:0 10px;
}
.classreturn .return{
position:absolute;
left:15px
}
.classreturn .return a{
overflow:hidden;
display:block
}
.classreturn .return a img{
width:12px;
height:22px
}
.classreturn .tit{
font-size:1.125rem;
}
.classreturn .tit .sear-input{
width:12.544rem;
height:1.23733rem
}
.classreturn .tit .sear-input a{
display:block
}
.classreturn .tit .sear-input input{
border:0;
width:100%;
height:1.23733rem;
color:#666666;
outline:none;
padding:0 .21333rem;
font-size:.59733rem;
display:inherit
}
.classreturn .nav_menu{
position:absolute;
right:15px
}
.classreturn .nav_menu a{
display:block
}
.classreturn .nav_menu img{
width:20px
}
.ds-in-bl{
display:inline-block;
vertical-align:middle;
*vertical-align:auto;
*zoom:1;
*display:inline
}
.classreturn{background-color:#f8f8f8;border-bottom:1px solid #dedede;position:relative;text-align:center;line-height:50px;padding:0 10px;}
.classreturn .return{position:absolute;left:15px}
.classreturn .return a{overflow:hidden;display:block}
.classreturn .return a img{width:12px;height:22px}
.classreturn .tit{font-size:1.125rem;}
.classreturn .tit .sear-input{width:12.544rem;height:1.23733rem}
.classreturn .tit .sear-input a{display:block}
.classreturn .tit .sear-input input{border:0;width:100%;height:1.23733rem;color:#666666;outline:none;padding:0 .21333rem;font-size:.59733rem;display:inherit}
.classreturn .nav_menu{position:absolute;right:15px}
.classreturn .nav_menu a{display:block;color:#999;}
.classreturn .nav_menu img{width:20px}
.ds-in-bl{display:inline-block;vertical-align:middle;*vertical-align:auto;*zoom:1;*display:inline}
.tpnavf{display:none;}
.tpnavf .nav_list{-moz-box-shadow:0 0 0 0 rgba(255,255,255,0);-webkit-box-shadow:0 0 0 0 rgba(255,255,255,0);box-shadow:0 0 0 0 rgba(255,255,255,0);border-bottom:1px solid #f0f2f5;background-color:#404042;}

86
resources/views/admin/WeixinMenu/add.blade.php

@ -0,0 +1,86 @@
@extends('admin.layouts.app')
@section('title', '栏目添加')
@section('content')
<h5 class="sub-header"><a href="/fladmin/weixinmenu">栏目管理</a> > 栏目添加</h5>
<form method="post" action="/fladmin/weixinmenu/doadd" role="form" id="addcat" class="table-responsive">{{ csrf_field() }}
<table class="table table-striped table-bordered">
<tbody>
<tr>
<td align="right">名称:</td>
<td><input name="name" type="text" id="name" size="30" class="required"></td>
</tr>
<tr>
<td align="right">上级菜单:</td>
<td><?php if($id==0){echo "顶级栏目";}else{echo $postone["name"];} ?><input style="display:none;" type="text" name="prid" id="prid" value="<?php if($id==0){echo "top";}else{echo $id;} ?>"></td>
</tr>
<tr>
<td align="right">菜单的响应动作类型:</td>
<td><input name="type" type="text" value="" id="type" style="width:30%"> <small>(view表示网页,click表示点击,miniprogram表示小程序)</small></td>
</tr>
<tr>
<td align="right">菜单KEY值:</td>
<td><input name="key" id="key" type="text" value="" size="30"> <small>(click等点击类型必须)</small></td>
</tr>
<tr>
<td align="right">网页链接:</td>
<td><input name="url" id="url" type="text" value="" size="50"> <small>(view、miniprogram类型必须)</small></td>
</tr>
<tr>
<td align="right">media_id:</td>
<td><input name="media_id" type="text" style="width:70%" id="media_id" class="alltxt" value=""></td>
</tr>
<tr>
<td align="right">appid:</td>
<td><input name="appid" type="text" style="width:50%" id="appid" class="alltxt" value=""></td>
</tr>
<tr>
<td align="right">pagepath:</td>
<td><input name="pagepath" type="text" style="width:50%" id="pagepath" class="alltxt" value=""></td>
</tr>
<tr>
<td align="right">是否显示:</td>
<td>
<input type="radio" value='0' name="is_show" checked />&nbsp;&nbsp;&nbsp;
<input type="radio" value='1' name="is_show" />&nbsp;
</td>
</tr>
<tr>
<td colspan="2"><input type="submit" class="btn btn-success" value="保存(Submit)">&nbsp;&nbsp;<input type="reset" class="btn btn-default" value="重置(Reset)"></td>
</tr>
</tbody>
</table>
</form><!-- 表单结束 -->
<script>
$(function(){
$(".required").blur(function(){
var $parent = $(this).parent();
$parent.find(".formtips").remove();
if(this.value=="")
{
$parent.append(' <small class="formtips onError"><font color="red">不能为空!</font></small>');
}
else
{
$parent.append(' <small class="formtips onSuccess"><font color="green">OK</font></small>');
}
});
//重置
$('#addcat input[type="reset"]').click(function(){
$(".formtips").remove();
});
});
$('#addcat input[type="submit"]').click(function(){
$(".required").trigger('blur');
var numError = $('#addcat .onError').length;
if(numError){
return false;
}
});
</script>
@endsection

82
resources/views/admin/WeixinMenu/edit.blade.php

@ -0,0 +1,82 @@
@extends('admin.layouts.app')
@section('title', '菜单修改')
@section('content')
<h5 class="sub-header"><a href="/fladmin/weixinmenu">菜单管理</a> > 菜单修改</h5>
<form method="post" action="/fladmin/weixinmenu/doedit" role="form" id="addcat" class="table-responsive">{{ csrf_field() }}
<table class="table table-striped table-bordered">
<tbody>
<tr>
<td align="right">名称:</td>
<td><input name="name" type="text" value="<?php echo $post["name"]; ?>" id="name" size="30" class="required"><input style="display:none;" type="text" name="id" id="id" value="<?php echo $id; ?>"></td>
</tr>
<tr>
<td align="right">菜单的响应动作类型:</td>
<td><input name="type" type="text" value="<?php echo $post["type"]; ?>" id="type" style="width:30%"> <small>(view表示网页,click表示点击,miniprogram表示小程序)</small></td>
</tr>
<tr>
<td align="right">菜单KEY值:</td>
<td><input name="key" id="key" type="text" value="<?php echo $post["key"]; ?>" size="30"> <small>(click等点击类型必须)</small></td>
</tr>
<tr>
<td align="right">网页链接:</td>
<td><input name="url" id="url" type="text" value="<?php echo $post["url"]; ?>" size="50"> <small>(view、miniprogram类型必须)</small></td>
</tr>
<tr>
<td align="right">media_id:</td>
<td><input name="media_id" type="text" style="width:70%" id="media_id" class="alltxt" value="<?php echo $post["media_id"]; ?>"></td>
</tr>
<tr>
<td align="right">appid:</td>
<td><input name="appid" type="text" style="width:50%" id="appid" class="alltxt" value="<?php echo $post["appid"]; ?>"></td>
</tr>
<tr>
<td align="right">pagepath:</td>
<td><input name="pagepath" type="text" style="width:50%" id="pagepath" class="alltxt" value="<?php echo $post["pagepath"]; ?>"></td>
</tr>
<tr>
<td align="right">是否显示:</td>
<td>
<input type="radio" value='0' name="is_show" <?php if(isset($post['is_show']) && $post['is_show']==0){echo 'checked';} ?> />&nbsp;是&nbsp;&nbsp;
<input type="radio" value='1' name="is_show" <?php if(isset($post['is_show']) && $post['is_show']==1){echo 'checked';} ?> />&nbsp;否
</td>
</tr>
<tr>
<td colspan="2"><input type="submit" class="btn btn-success" value="保存(Submit)">&nbsp;&nbsp;<input type="reset" class="btn btn-default" value="重置(Reset)"></td>
</tr>
</tbody>
</table>
</form><!-- 表单结束 -->
<script>
$(function(){
$(".required").blur(function(){
var $parent = $(this).parent();
$parent.find(".formtips").remove();
if(this.value=="")
{
$parent.append(' <small class="formtips onError"><font color="red">不能为空!</font></small>');
}
else
{
$parent.append(' <small class="formtips onSuccess"><font color="green">OK</font></small>');
}
});
//重置
$('#addcat input[type="reset"]').click(function(){
$(".formtips").remove();
});
});
$('#addcat input[type="submit"]').click(function(){
$(".required").trigger('blur');
var numError = $('#addcat .onError').length;
if(numError){
return false;
}
});
</script>
@endsection

32
resources/views/admin/WeixinMenu/index.blade.php

@ -0,0 +1,32 @@
@extends('admin.layouts.app')
@section('title', '微信公众号自定义菜单列表')
@section('content')
<h2 class="sub-header">微信自定义菜单</h2>[ <a href="/fladmin/weixinmenu/add">增加顶级菜单</a> ] [ <a onclick="createmenu_confirm('/fladmin/weixinmenu/createmenu')" href="javascript:;">生成菜单</a> ]<br><br>
<form name="listarc"><div class="table-responsive">
<table class="table table-striped table-hover">
<thead><tr><th>ID</th><th>名称</th><th>菜单动作类型</th><th>是否显示</th><th>更新时间</th><th>操作</th></tr></thead>
<tbody id="cat-list">
<?php if($catlist){foreach($catlist as $row){ ?>
<tr id="cat-<?php echo $row["id"]; ?>">
<td><?php echo $row["id"]; ?></td>
<td><?php if($row["pid"]!=0){echo "";}echo $row["name"]; ?></td><td><?php echo $row["type"]; ?></td><td><?php if($row["is_show"]==0){echo '是';}else{echo '<font color="red">否</font>';} ?></td><td><?php echo date('Y-m-d',$row["addtime"]); ?></td>
<td><?php if($row["pid"]==0){ ?><a href="/fladmin/weixinmenu/add?reid=<?php echo $row["id"]; ?>">增加子类</a> | <?php } ?><a href="/fladmin/weixinmenu/edit?id=<?php echo $row["id"]; ?>">更改</a> | <a onclick="delconfirm('/fladmin/weixinmenu/del?id=<?php echo $row["id"]; ?>')" href="javascript:;">删除</a></td>
</tr><?php }} ?>
</tbody></table></div><!-- 表格结束 --></form><!-- 表单结束 -->
<script>
function createmenu_confirm(url)
{
if(confirm("确定要重新生成微信自定义菜单吗?"))
{
location.href= url;
}
else
{
}
}
</script>
@endsection

31
resources/views/weixin/goods/goodsDetail.blade.php

@ -179,7 +179,20 @@ function cart_num_add()
function dosubmit()
{
var url = '<?php echo env('APP_API_URL').'/cart_add'; ?>';
var access_token = '<?php echo $_SESSION['weixin_user_info']['access_token']; ?>';
var access_token = '<?php if(isset($_SESSION['weixin_user_info']['access_token'])){echo $_SESSION['weixin_user_info']['access_token'];} ?>';
if(access_token=='')
{
//提示
layer.open({
content: '请先登录'
,skin: 'msg'
,time: 2 //2秒后自动关闭
});
setTimeout("location.href = '<?php echo route('weixin_login',array('return_url'=>route('weixin_goods_detail',array('id'=>$post['id'])))); ?>'",1000);
return false;
}
var cart_type = $("#cart_type").val();
var goods_number = $("#num").val();
@ -219,9 +232,23 @@ function dosubmit()
function collect_goods()
{
var url = '<?php if(isset($post['is_collect']) && $post['is_collect']>=1){echo env('APP_API_URL').'/collect_goods_delete';}else{echo env('APP_API_URL').'/collect_goods_add';} ?>';
var access_token = '<?php echo $_SESSION['weixin_user_info']['access_token']; ?>';
var access_token = '<?php if(isset($_SESSION['weixin_user_info']['access_token'])){echo $_SESSION['weixin_user_info']['access_token'];} ?>';
var goods_id = $("#id").val();
if(access_token=='')
{
//提示
layer.open({
content: '请先登录'
,skin: 'msg'
,time: 2 //2秒后自动关闭
});
setTimeout("location.href = '<?php echo route('weixin_login',array('return_url'=>route('weixin_goods_detail',array('id'=>$post['id'])))); ?>'",1000);
return false;
}
$.post(url,{access_token:access_token,goods_id:goods_id},function(res)
{
if(res.code==0)

6
resources/views/weixin/user/index.blade.php

@ -44,7 +44,7 @@
<div class="floor my g4">
<div class="content">
<!--订单管理模块-s-->
<div class="floor myorder ma-to-20 p">
<div class="floor myorder mt10">
<div class="content30">
<div class="order">
<div class="fl">
@ -95,7 +95,7 @@
<!--订单管理模块-e-->
<!--资金管理-s-->
<div class="floor myorder ma-to-20 p">
<div class="floor myorder mt10">
<div class="content30">
<div class="order">
<div class="fl">
@ -136,7 +136,7 @@
</div>
<!--资金管理-e-->
<div class="floor list7 ma-to-20">
<div class="floor list7 mt10">
<div class="myorder p">
<div class="content30">
<a href="javascript:void(0);" onclick="alert('请购买商业正版哦!');">

8
routes/web.php

@ -327,6 +327,14 @@ Route::group(['prefix' => 'fladmin', 'namespace' => 'Admin', 'middleware' => ['w
Route::get('/menu/edit', 'MenuController@edit')->name('admin_menu_edit');
Route::post('/menu/doedit', 'MenuController@doedit')->name('admin_menu_doedit');
Route::get('/menu/del', 'MenuController@del')->name('admin_menu_del');
//微信自定义菜单管理
Route::get('/weixinmenu', 'WeixinMenuController@index')->name('admin_weixinmenu');
Route::get('/weixinmenu/add', 'WeixinMenuController@add')->name('admin_weixinmenu_add');
Route::post('/weixinmenu/doadd', 'WeixinMenuController@doadd')->name('admin_weixinmenu_doadd');
Route::get('/weixinmenu/edit', 'WeixinMenuController@edit')->name('admin_weixinmenu_edit');
Route::post('/weixinmenu/doedit', 'WeixinMenuController@doedit')->name('admin_weixinmenu_doedit');
Route::get('/weixinmenu/del', 'WeixinMenuController@del')->name('admin_weixinmenu_del');
Route::get('/weixinmenu/createmenu', 'WeixinMenuController@createmenu')->name('admin_weixinmenu_createmenu'); //生成自定义菜单
//后台登录注销
Route::get('/login', 'LoginController@login')->name('admin_login');
Route::post('/dologin', 'LoginController@dologin')->name('admin_dologin');

Loading…
Cancel
Save