1. 到极光推送官网下载PHP SDK http://docs.jpush.io/server/php_sdk/
2. 解压vendor.tar.gz到您的项目,ThinkPHP/Library/Vendor/下
3. 在应用文件夹的home模块Controller下创建一个JpushController文件
Php 代码:
‘;
$client = new JPushClient(‘64237c873a665c79b1ece96c‘, ‘41aeddfab4828ddb64a5a1f1‘);
try {
$result = $client->push()
->setPlatform(M\all)
->setAudience(M\all)
->setNotification(M\notification(‘Hi, JPush‘,
M\android(‘Hi, Android‘, ‘Message Title‘, 1,array("key1"=>"value1","key2"=>"value2","key3"=>"value3"))
))
->setMessage(M\message(‘Message Content‘, ‘Message Title1‘, ‘Message Type‘, array("key1"=>"value1","key2"=>"value2","key3"=>"value3")))
->send();
echo ‘Push Success.‘ . $br;
echo ‘sendno : ‘ . $result->sendno . $br;
echo ‘msg_id : ‘ .$result->msg_id . $br;
echo ‘Response JSON : ‘ . $result->json . $br;
} catch (APIRequestException $e) {
echo ‘Push Fail.‘ . $br;
echo ‘Http Code : ‘ . $e->httpCode . $br;
echo ‘code : ‘ . $e->code . $br;
echo ‘message : ‘ . $e->message . $br;
echo ‘Response JSON : ‘ . $e->json . $br;
echo ‘rateLimitLimit : ‘ . $e->rateLimitLimit . $br;
echo ‘rateLimitRemaining : ‘ . $e->rateLimitRemaining . $br;
echo ‘rateLimitReset : ‘ . $e->rateLimitReset . $br;
} catch (APIConnectionException $e) {
echo ‘Push Fail.‘ . $br;
echo ‘message‘ . $e->getMessage() . $br;
}
}
}