25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 
 
 
 

52 satır
1.1 KiB

  1. <?php
  2. /**
  3. * *************************************************************************
  4. *
  5. * Copyright (c) 2014 Baidu.com, Inc. All Rights Reserved
  6. *
  7. * ************************************************************************
  8. */
  9. /**
  10. *
  11. * @file hello.php
  12. * @encoding UTF-8
  13. *
  14. *
  15. * @date 2015年3月10日
  16. *
  17. */
  18. require_once './sdk.php';
  19. // 创建SDK对象.
  20. $sdk = new PushSDK();
  21. $channelId = '4295678255320590855';
  22. // message content.
  23. $message = array (
  24. // 消息的标题.
  25. 'title' => 'Hi!',
  26. // 消息内容
  27. 'description' => "hello, this message from baidu push service test."
  28. );
  29. // 设置消息类型为 通知类型.
  30. $opts = array (
  31. 'msg_type' => 0
  32. );
  33. // 向目标设备发送一条消息
  34. $rs = $sdk -> pushMsgToSingleDevice($channelId, $message, $opts);
  35. // 判断返回值,当发送失败时, $rs的结果为false, 可以通过getError来获得错误信息.
  36. if($rs === false){
  37. print_r($sdk->getLastErrorCode());
  38. print_r($sdk->getLastErrorMsg());
  39. }else{
  40. // 将打印出消息的id,发送时间等相关信息.
  41. print_r($rs);
  42. }
  43. echo "done!";