用户
 找回密码
 入住 CI 中国社区
搜索
查看: 8984|回复: 13
收起左侧

[库 Library] 接口功能完善的微信开发类库

[复制链接]
发表于 2015-10-22 21:54:29 | 显示全部楼层 |阅读模式
在论坛找了好久,发现微信相关的库比较少,而且功能都要自己去扩展,而github和开源中国社区的类库又都要改动不少地方才能适配CI框架,于是今天终于自己动手然后综合了几个开源类库的一些方法完善了它,在些分享,新人发贴,希望指教。。。。。。
主要代码来源:https://github.com/dodgepudding/wechat-php-sdk

进入正题
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
使用方法:
其实类的最上方有的,方便用的时候可以看一下

控制器代码
PHP复制代码
 
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
//include("../wechat.class.php");
class Test extends CI_Controller {
 
 
public function __construct() {
                parent::__construct();
                        $params = array(
                                'token'=>'weixin', //填写你设定的key
                                'encodingaeskey'=>'encodingaeskey', //填写加密用的EncodingAESKey
                                'appid'=>'ddfgggffrff01add', //填写高级调用功能的app id
                                'appsecret'=>'39ea2b********************' //填写高级调用功能的密钥
                        );
                 //这个$params必须在构造函数传参,因为类库在构造函数中$this->appid = isset($params['appid'])?$params['appid']:'';
                $this->load->library('wechat/wechat',$params);
            }
           
        public function index (){
                $this->wechat->valid();
                $type=$this->wechat->getRev()->getRevType();
                switch($type) {
                        case Wechat::MSGTYPE_TEXT:
                                $this->wechat->text("hello, I'm 文本")->reply();
                                exit;
                                break;
                        case Wechat::MSGTYPE_EVENT:
                                $this->wechat->text("hello, 我是事件")->reply();
                                exit;
                                break;
                        case Wechat::MSGTYPE_IMAGE:
                                $this->wechat->text("hello, I'm 图片")->reply();
                                exit;
                                break;
                        default:
                                $this->wechat->text("我是未知")->reply();
                }
        }
 
}
 
复制代码

具体的方法自己研究!

Wechat.rar

27.01 KB, 下载次数: 483

发表于 2017-6-22 22:54:39 | 显示全部楼层
请问 微信配置token 如何配置啊 我老失败 请给个CI完整代码包 谢谢。
打开网页显示 An Error Was Encountered

Unable to load the requested class: session
class Wx extends CI_Controller
$this->load->library('wechat/wechat',$params);
$this->load->library('Wechat',$params); 我是这么写的才能找到 就是在liB目录

  'encodingaeskey'=>'encodingaeskey', //填写加密用的EncodingAESKey 这个不知道用不用改 我没地方设置。

访问这个 xx.xxx.com/index.php/wx/index 微信公众号上配置这个URL 通不过 ,请告知如何配置。谢谢
 楼主| 发表于 2016-11-2 14:31:44 | 显示全部楼层
censtart 发表于 2016-7-19 16:51
$this->load->library('wechat/wechat',$params);.好像应该是大写Wechat吧

是的  装载类库注意大小写,谢谢指正
发表于 2015-10-23 09:00:53 | 显示全部楼层
http://www.ifixedbug.com/posts/codeigniter-weixin-library
我封装的一个微信CI类库,用的和你一样的原生类库,逻辑转移到类库了,控制器很简单。
发表于 2015-10-23 11:28:43 | 显示全部楼层
thx 楼主,刚好最近在做微信业务
发表于 2015-12-8 16:30:37 | 显示全部楼层
谢谢分享,学习了
发表于 2015-12-15 14:34:22 | 显示全部楼层
感谢!!!非常感谢
发表于 2016-7-19 16:51:14 | 显示全部楼层
$this->load->library('wechat/wechat',$params);.好像应该是大写Wechat吧
发表于 2016-7-19 19:09:56 | 显示全部楼层
接口类中$_GET无法获取参数是什么原因?
 楼主| 发表于 2016-11-2 14:32:44 | 显示全部楼层
censtart 发表于 2016-7-19 19:09
接口类中$_GET无法获取参数是什么原因?

具体的,报了什么错?
发表于 2016-12-13 11:30:23 | 显示全部楼层
谢谢分享 顺便问一下 CI框架的微信后台系统 有资源吗 谢谢

本版积分规则