php微信
来源:互联网 发布:xampp mysql mac设置 编辑:程序博客网 时间:2024/05/24 15:37
封装curl
public function http_curl($url, $type = 'get', $res = 'json', $arr = ''){ $cl = curl_init(); curl_setopt($cl, CURLOPT_URL, $url); curl_setopt($cl, CURLOPT_RETURNTRANSFER, 1); if($type == 'post'){ curl_setopt($cl, CURLOPT_POST, 1); curl_setopt($cl, CURLOPT_POSTFIELDS, $arr); } $output = curl_exec($cl); curl_close($cl); if($res == 'json'){ if( curl_error($cl)){ return curl_error($cl); }else{ return json_decode($output, true); } } }
post
// 创建微信自定义菜单 public function WxMenu(){ $access_token = $this->getWxAccessToken(); $url = 'https://api.weixin.qq.com/cgi-bin/menu/create?access_token=' . $access_token; $postArr = array( 'button' => array( //第一个一级菜单 array( 'name' => urlencode('菜单一'), 'type' => 'click', 'key' => 'video', ), //第二个一级菜单 array( 'name' => urlencode('菜单二'), 'sub_button' => array( array( 'name' => urlencode('歌曲'), 'type' => 'click', 'key' => 'songs', ), array( 'name' => urlencode('电影'), 'type' => 'view', 'url' => 'http://www.baidu.com', ), ), ), //第三个一级菜单 array( 'name' => urlencode('菜单三'), 'type' => 'view', 'url' => 'http://www.qq.com', ), ), ); $postJson = urldecode( json_encode($postArr) ); //post $res = $this->http_curl($url, 'post', 'json', $postJson); }
get
// 获取微信服务器IP地址 public function getWxServerIp(){ $access_token = $this->getWxAccessToken(); $url = 'https://api.weixin.qq.com/cgi-bin/getcallbackip?access_token='.$access_token; //get $res = $this->http_curl($url,'get','json'); }
阅读全文
0 0
- php 微信1
- PHP 微信开发
- php微信支付
- 微信支付PHP
- php集成微信
- php微信支付
- php微信
- php微信
- php微信
- php微信
- php微信
- php微信
- php微信
- php微信
- php微信
- php开发微信
- PHP微信分享
- php开发微信demo
- Jquery实现鼠标移动/移过到商品小图片上时替换掉大图片上的图片
- 在java中wait和sleep方法的不同?
- Unit testing framework
- S
- 自学Java之准备
- php微信
- 算法学习----反转链表
- postgres备份延伸之配置centos的文件夹相关权限
- 集群与负载均衡系列(8)——redis主从复制+哨兵实现高可用性架构
- expected at least 1 bean which qualifies as autowire candidate.
- 我在一个基础协议中增加了一个字段, 导致同事core dump了!
- 1834: [ZJOI2010]network 网络扩容
- 关于myBatis与SQLserver 配合使用,查询类型为Date的数据时,日期会减少两天的问题
- 基数排序