Toggle navigation
菜菜小站
菜菜小站
前端开发
前端开发
前端基础
bootstrap
JavaScript
后端开发
后端开发
php开发
laravel
数据库
编辑器
git
服务器
服务器
https
cos云存储
ubuntu
homestead
微信开发
微信开发
微信小程序
python开发
python开发
python基础
关于
微信公众号开发
作者:
菜菜子
|
时间:2017-03-15 19:21:00 |
分类:
前端开发
,
php开发
,
后端开发
,
微信开发
|
访问: 938 次|
评论:
0 评论
```php access_token = $this->get_cookie_access_token(); if (empty($this->access_token)) { $this->access_token = $this->get_new_access_token(); } $this->jsApiTicket = $this->get_cookie_jsApiTicket(); if (empty($this->jsApiTicket)) { $this->jsApiTicket = $this->get_new_jsApiTicket(); } } /*获取用户列表*/ function get_user_list() { $url = "https://api.weixin.qq.com/cgi-bin/user/get?access_token=" . $this->access_token; $result = file_get_contents($url); $jsoninfo = json_decode($result, true); $userlist = $jsoninfo['data']['openid']; return $userlist; } /*创建分组*/ function create_group($groupname) { $url = "https://api.weixin.qq.com/cgi-bin/groups/create?access_token=" . $this->access_token; $group = array("group" => array("name" => $groupname)); $jsonStr = json_encode($group); $retu = $this->https_request($url, $jsonStr); return $retu; } /*查询用户所在分组*/ function query_group($openid) { $url = "https://api.weixin.qq.com/cgi-bin/groups/getid?access_token=" . $this->access_token; $group = array("openid" => $openid); $jsonStr = json_encode($group); $retu = $this->https_request($url, $jsonStr); return $retu; } /*获取分组列表*/ function get_group_list() { $url = "https://api.weixin.qq.com/cgi-bin/groups/get?access_token=" . $this->access_token; $result = file_get_contents($url); $jsoninfo = json_decode($result, true); return $jsoninfo["groups"]; } /*根据分组id查分组名称*/ // 这个方法有点变态 // **** 不能有重复组的名称出现********//// function get_groupName_by_groupId($groupID) { // 获取分组 $returnGroupList = $this->get_group_list(); // 查找组名所在父级键名 $fid = array_search($groupID, array_column($returnGroupList, 'id')); //返回对应的id值 return @$returnGroupList[$fid]["name"]; } /*根据分组名查分组id*/ // 这个方法有点变态 // **** 不能有重复组的名称出现********//// function get_groupId_by_groupName($groupName) { // 获取分组 $returnGroupList = $this->get_group_list(); // 查找组名所在父级键名 $fid = array_search($groupName, array_column($returnGroupList, 'name')); //返回对应的id值 return @$returnGroupList[$fid]["id"]; } // 查找重复的组 function aa() { $arr = Array( '0' => Array('id' => 0, 'name' => '未分组', 'count' => 0), '1' => Array('id' => 1, 'name' => '黑名单', 'count' => 0), '2' => Array('id' => 2, 'name' => '新标组', 'count' => 5), '3' => Array('id' => 103, 'name' => '1-1-3', 'count' => 1), '4' => Array('id' => 104, 'name' => '1-1-3', 'count' => 1) ); $tarStr = "1-1-3"; $keys = array_keys(array_column($arr, 'name'), $tarStr); var_dump($keys); // array(2) { // [0]=> // int(3) // [1]=> // int(4) // } } /*移动用户分组*/ function move_group($openid, $groupid) { $url = "https://api.weixin.qq.com/cgi-bin/groups/members/update?access_token=" . $this->access_token; $group = array("openid" => $openid, "to_groupid" => $groupid); $jsonStr = json_encode($group); $retu = $this->https_request($url, $jsonStr); return $retu; } /*删除分组*/ function delete_group($groupid) { $url = "https://api.weixin.qq.com/cgi-bin/groups/delete?access_token=" . $this->access_token; $group = array("group" => array("id" => $groupid)); $jsonStr = json_encode($group); $retu = $this->https_request($url, $jsonStr); return $retu; } /*设置用户备注名*/ function update_remark($openid, $remark) { $url = "https://api.weixin.qq.com/cgi-bin/user/info/updateremark?access_token=" . $this->access_token; $group = array("openid" => $openid, "remark" => $remark); $jsonStr = json_encode($group); $retu = $this->https_request($url, $jsonStr); return $retu; } /*获取单个用户基本信息*/ function get_person_info($openid) { $url = "https://api.weixin.qq.com/cgi-bin/user/info?access_token=" . $this->access_token . "&openid=" .$openid. "&lang=zh_CN"; $result = file_get_contents($url); $person_info = json_decode($result, true); //print_r($person_info); //return preg_replace("#\\\u([0-9a-f]{4})#ie", "iconv('UCS-2BE', 'UTF-8', pack('H4', '\\1'))", $person_info); return $person_info; } /*批量获取用户基本信息*/ function get_more_person_info() { $url = "https://api.weixin.qq.com/cgi-bin/user/info/batchget?access_token=" . $this->access_token; $group = array("userlist" => array(array("openid=>" => ""), array("openid=>" => ""))); $jsonStr = json_encode($group); $retu = $this->https_request($url, $jsonStr); return $retu; } // 网页使用code换取openid function get_openid_by_web() { if (isset($_GET["code"])) { $code = $_GET['code'];//获取code } else { $code = ''; } $weixin = file_get_contents("https://api.weixin.qq.com/sns/oauth2/access_token?appid=" . self::APPID . "&secret=" . self::APPSECRET . "&code=" . $code . "&grant_type=authorization_code");//通过code换取网页授权access_token $jsondecode = json_decode($weixin); //对JSON格式的字符串进行编码 $array = get_object_vars($jsondecode);//转换成数组 return @$array['openid'];//输出openid } /*获取用户列表*/ function get_users_info() { $url = "https://api.weixin.qq.com/scan/merchantinfo/get?access_token=" . $this->access_token; $result = file_get_contents($url); $jsoninfo = json_decode($result, true); return $jsoninfo; } private function get_cookie_jsApiTicket() { $res = file_get_contents(dirname(__FILE__).'/jsTicket.yb'); $result = explode(',', $res); $checktime = time()- $result[2]; if ($checktime < 7200) { return $this->jsApiTicket = $result[0]; } else { return $this->get_new_jsApiTicket(); } } private function get_new_jsApiTicket() { $url = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=" . $this->access_token . "&type=jsapi"; $res = file_get_contents($url); $result = json_decode($res, true); $put = $result["ticket"] . ',' . $result['expires_in'] . ',' . time(); file_put_contents(dirname(__FILE__).'/jsTicket.yb', $put); return $this->jsApiTicket = $result['ticket']; } // http://www.bubuko.com/infodetail-1648797.html private function https_request($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; } private function get_cookie_access_token() { $res = file_get_contents(dirname(__FILE__).'/access_token.yb'); $result = explode(',', $res); $checktime = time() - $result[2]; if ($checktime < 7200) { return $this->access_token = $result[0]; } else { return $this->get_new_access_token(); } } private function get_new_access_token() { $token_access_url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" . self::APPID . "&secret=" . self::APPSECRET . ""; $res = file_get_contents($token_access_url); $result = json_decode($res, true); $put = $result["access_token"] . ',' . $result['expires_in'] . ',' . time(); file_put_contents(dirname(__FILE__)."/access_token.yb", $put); return $this->access_token = $result['access_token']; } } ```
标签:
还不快抢沙发
添加新评论
昵称(必填)
邮箱(必填)
网站(选填)
内容(必填)
提交评论
最新文章
ubuntu自动化安装php文件
laravel 操作redis
laravel-admin静态资源加速
laravel-admin1.6版本表单tag bug修复方法
laravel根据另外一列的值赋予grid某一列editable()
laravel-admin数据来源非数据表信息
laravel判定多对多关系是否存在
最新回复
局外人: 下载失败了,大佬帮忙看看是什么原因呢?
青丝: 7355763
菜菜子: 我好像沒有做這個提示,方便加微信吧,我看看什麼問題
青丝: 对的,提示需要8.0PHP
菜菜子: 你版本不對吧
菜菜子: 你是typecho1.2?用的是https://git...
青丝: 服务器PHP最高只有7.4 启用插件失败,有没有低PH...
newzuo: Argument 2 passed to Typech...
菜菜子: github更新了,重新下一个吧
刚下飞机的打工人: 可能是PHP版本的问题,在PHP8.0 typecho...
标签
bootstrap
前端框架
laravel5
laravel
laravel-admin
gd库
微信小程序
表单
https
git
wamp配置
ajax
cos小工具
cos
cos插件
微信支付
邮件发送
腾讯云
sql语言
jwt
typecho
数组
破解
编辑器
ubuntu
vue
homestead
linux
websocket
swoole
nginx
标签
刷新
加密处理
验证码
悬浮框
权限控制
markdown
shell
mysql
elasticsearch
ui
任务调度
定时任务
deployer
gogs
反向代理
ftp
测试
分页
队列
微信公众号
日志
wnmp
vagrant
无限极分类
分销
集合
supervisor
部署
grid
redis
python
归档
2019年01月
2018年12月
2018年11月
2018年10月
2018年09月
2018年08月
2018年07月
2018年06月
2018年05月
2018年04月
2018年03月
2017年09月
2017年06月
2017年05月
2017年04月
2017年03月
2017年02月
2017年01月
2016年12月
2016年11月
友情链接
空
//