JMessage API PHP Client

Github

This is a development package in PHP version for the JMessage REST API. It is provided by the JPush officially and generally supports the latest API functionality.

Corresponding REST API documentation: https://docs.jiguang.cn/jmessage/server/rest_api_im/

Supported PHP versions: 5.4 ~ 5.6.x, 7

Installation

Install by Composer

  • Add the jmessage dependency in the project’s composer.json file
  1. "require": {
  2. "jiguang/jmessage": "~1.1"
  3. }
  • Perform a $ php composer.phar install or $ composer install to install

Download source code directly to install

Directly download source code is also a method to install SDK. However, because of maintenance problems of version updates, this type of installation is not recommended. Composer cannot be used sometimes due to various reasons. Therefore, we also provide backups for this situation.

  • Download the source code package and unzip it into the project
  • Introduce autoload in the project (in the root directory of source code)
  1. require 'path_to_sdk/autoload.php';

Usage

Examples

Note: This is just a sample and should not be used directly in the actual environment!!

There is a simple sample code in the project’s examples folder. Developers can refer to the examples for a quick understanding of how to use the library.

Note: The downloaded sample code cannot be used immediately. You need to fill in the examples/config.php with the necessary parameters, or set the relevant environment variables. If you do not do this, the sample operation will fail. In addition to protecting developer privacy, examples/config.php file is not in version control and needs to be manually copied by using the following command:

  1. $ cp examples/config.php.example examples/config.php

Simple of example usage

To run the sample code in friend_examples.php

  1. # 假定当前目录为 JMessage 源码所在的根目录
  2. $ php examples/friend_examples.php

Of course, you can also edit the relevant sample file and change the parameters to see the implementation effect.

ErrorCode

Error code reported by the JMessage server. It may appear in the return value, which can be queried here: https://docs.jiguang.cn/jmessage/client/im_errorcode_server/

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/jpush/jmessage-api-php-client.

License

The library is available as open source under the terms of the MIT License.