Download the PHP package yuanshe/wechat-sdk without Composer

On this page you can find all versions of the php package yuanshe/wechat-sdk. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package wechat-sdk

足够简洁的微信公众平台接口封装,只需要简单的配置即可轻松使用公众平台接口

PS: 使用此工具前需要对微信公众平台对接流程有一定了解,或结合微信官方文档使用

特点

运行环境

PHP7已全面流行,PHP官方也不再提供PHP5的支持,因此项目不会考虑PHP7以下版本的兼容

安装

基本示例

example目录下是常见使用示例,使用方式可参考 example说明

开始

Tips: 项目主命名空间为Yuanshe\WeChatSDK,说明中出现的类名称均省略命名空间

初始化

使用任何功能前,要实例化一个WeChat对象,所有功能都是通过这个对象调用

配置

配置参数以键值对数组的形式传入,以下为配置项列表:

参数 类型 必填 默认值 说明
appid string 可在公众平台查看
appsecret string 可在公众平台生成
account string 消息通知必填 公众平台"公众号设置"中的"微信号"或"原始ID"
token string 消息通知必填 与公众平台"服务器配置"中的Token一致即可
encrypt bool true 是否开启消息加密(公众平台安全模式为兼容模式时此选项才有效,否则根据公众平台自身设置决定是否加密)
ase_key string 开启消息加密时必填 消息加解密密钥
cache_prefix string 填写的appid 缓存前缀。请务必确保前缀在项目中的唯一性,防止与项目中其他缓存冲突
timeout int 0 接口请求超时时间,0为永不超时
ssl_verify bool true 是否启用SSL证书验证,生产环境下建议开启
api_domain string api.weixin.qq.com 公众平台接口域名。使用默认配置即可,也可根据微信官方文档所列出的节点填写

缓存类

为尽可能避免出现重复的代码和不必要的依赖,项目中仅定义了缓存接口,并交由开发者自行实现。开发者需要编写一个实现CacheInterface接口的类,可参考example/Cache (该文件仅供参考,实际开发时应尽量利用项目、框架中现有的缓存功能)

需要实现的方法:

接口调用

基本用法

接口以Model Class的形式封装,可以通过以下方式调用:

对于IDE使用者,更推荐以属性的形式调用,因为IDE可以自动提示和补全。但无论使用哪种调用方式,都应区分大小写

Demo

获取关注用户列表:

获取公众号菜单内容:

Throws

如果公众平台接口返回错误码,程序会抛出ModelException异常,可以通过getCodegetMessage方法获取错误码和错误消息,getModel方法可以获取到Model名称

Model列表

更多接口正在完善中...

消息通知

用于接收公众号的事件推送以及用户消息,并可以自动回复用户

验证通知来源

为确保进一步安全,可验证消息来源IP是否在微信服务器列表中。此步骤非必须

接收消息

处理消息

Notify对象中包含消息的所有信息,可用以下方法获取:

回复消息

Notify类已封装消息回复方法,方法将数据处理成字符串后返回,开发者将其输出即可

方法用法及列表如下

授权登录

参考example/oauth.php

JS-SDK

调用$wechat->jsSdk方法,将返回值转换为JS对象,前端传参给wx.config即可

参考example/jssdk.php

异常处理

此项目异常类的命名空间为Yuanshe\WeChatSDK\Exception,以下列出项目中定义的所有异常类,开发者可根据需要自行捕获处理

License

LGPL


All versions of wechat-sdk with dependencies

PHP Build Version
Package Version
Requires php Version ^7.0
ext-openssl Version *
ext-json Version *
ext-libxml Version *
ext-simplexml Version *
guzzlehttp/guzzle Version ^6.3
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package yuanshe/wechat-sdk contains the following files

Loading the files please wait ....