Example.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Administrator
  5. * Date: 2021/6/17
  6. * Time: 18:26
  7. */
  8. require_once __DIR__.'/vendor/autoload.php';
  9. date_default_timezone_set('PRC');
  10. class Example
  11. {
  12. //测试短信
  13. public function testSms()
  14. {
  15. /** 测试 */
  16. $app_id = 'xxxxxxxxxxxxxxxxxx';
  17. $app_secret = 'xxxxxxxxxxxxxxxxxx';
  18. $tpl_id = 'xxxxxxxxxxxxxxxxxx';
  19. $notify_obj = new Notify\Sms($app_id, $app_secret);
  20. $notify_obj->setTemplateId($tpl_id);
  21. $notify_obj->setAuthUser('xxxxxxxxxxxxxxxxxx');
  22. $notify_obj->setAuthPassword('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
  23. //群发+单发
  24. $url = 'http://xxxxxxxxxxxxxxxxxx/send-mass-msg';
  25. $sms_message = array(
  26. 'aaaa', 'cccc', 'xxxxx', date('Y-m-d')
  27. );
  28. $notify_obj->setSmsApiUrl($url);
  29. $notify_obj->setSmsMessage($sms_message);
  30. $rs = $notify_obj->sendSms('xxxxxxxxxxxxxxxxxx');
  31. var_dump($rs);
  32. //批量
  33. $url = 'http://xxxxxxxxxxxxxxxxxx/send-batch-msg';
  34. $params = array(
  35. array(
  36. 'mobiles' => 'xxxxxxxxxxxxxxxxxx',
  37. 'templateParams' => array('aaaa', 'cccc', 'xxxx', date('Y-m-d'))
  38. )
  39. );
  40. $notify_obj->setSmsApiUrl($url);
  41. $rs = $notify_obj->sendBatchSms($params);
  42. var_dump($rs);
  43. //发送验证码
  44. $url = 'http://xxxxxxxxxxxxxxxxxx/send-code';
  45. $sms_message = array(
  46. 'code' =>rand(1000,9999),
  47. 'mobile' =>'xxxxxxxxxxxxxxxxxx',
  48. );
  49. $notify_obj->setUrlQueryArr($sms_message);
  50. $notify_obj->setSmsApiUrl($url);
  51. $rs = $notify_obj->sendSms($sms_message['mobile']);
  52. var_dump($rs);
  53. }
  54. //测试APP推送消息
  55. public function testAppPush()
  56. {
  57. /** 测试 */
  58. $app_id = 'xxxxxxxxxxxxxx';
  59. $app_secret = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxx';
  60. $tpl_id = 7;
  61. $notify_obj = new Notify\AppPush($app_id, $app_secret);
  62. $notify_obj->setTemplateId($tpl_id);
  63. $notify_obj->setAuthUser('xxxxxxxxxxxxxx');
  64. $notify_obj->setAuthPassword('xxxxxxxxxxxxxx');
  65. //群发+单发
  66. $url = 'http://xxxxxxxxxxxxxx/cgi/notify/app/send-mass-msg';
  67. $message_arr = array(
  68. 'app'=>0,
  69. 'extraData'=>null,
  70. 'startTime'=>null,
  71. 'templateId'=>7,
  72. 'templateParams'=>null,
  73. 'uniqueKey'=>null,
  74. 'userIds'=>array('5645664'),
  75. );
  76. $notify_obj->setApiUrl($url);
  77. $rs = $notify_obj->send($message_arr);
  78. var_dump($rs);
  79. //批量
  80. $url = 'http://xxxxxxxxxxxxxx/cgi/notify/app/send-batch-msg';
  81. $message_arr = array(
  82. 'app'=>0,
  83. 'extraData'=>null,
  84. 'startTime'=>null,
  85. 'templateId'=>7,
  86. 'receivers'=>array(
  87. array(
  88. 'templateParams' => null,
  89. 'uniqueKey'=>null,
  90. 'userId'=>'5645664',
  91. )
  92. ),
  93. );
  94. $notify_obj->setApiUrl($url);
  95. $rs = $notify_obj->send($message_arr);
  96. var_dump($rs);
  97. }
  98. }
  99. $test = new Example();
  100. //$test->testSms();
  101. $test->testAppPush();