KFMessageControllerTest.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. namespace Tests\WechatPlatform\Http;
  3. use Modules\WechatPlatform\Http\Controllers\KFMessageController;
  4. use PHPUnit\Framework\TestCase;
  5. use Tests\UsedTestCase;
  6. class KFMessageControllerTest extends UsedTestCase
  7. {
  8. public function testAdd()
  9. {
  10. $STR = <<<AAA
  11. 文本内容<a href="http://www.qq.com" data-miniprogram-appid="appid" data-miniprogram-path="pages/index/index">点击跳小程序</a>
  12. AAA;
  13. $res = $this->withHeaders([
  14. 'Authorization' => 'Bearer '. $this->token,
  15. ])->json('post','http://localhost/api/wechatPlatform/kfMessage/add', [
  16. 'name' => 'liuzj-test-'. uniqid(),
  17. 'send_at' => date('Y-m-d H:i:s', strtotime('tomorrow')),
  18. 'message_type' => 1,
  19. 'u_type' => 1,
  20. 'message_content' => [
  21. ['text' => '普通文本👌🏻'],
  22. ['text' => $STR]
  23. ]
  24. ]);
  25. $this->dumpJson($res);
  26. }
  27. public function testList()
  28. {
  29. $res = $this->withHeaders([
  30. 'Authorization' => 'Bearer '. $this->token,
  31. ])->json('get','http://localhost/api/wechatPlatform/kfMessage/list', [
  32. ]);
  33. $this->dumpJson($res);
  34. }
  35. public function testupdateContent()
  36. {
  37. $res = $this->withHeaders([
  38. 'Authorization' => 'Bearer '. $this->token,
  39. ])->json('post','http://localhost/api/wechatPlatform/kfMessage/updateContent', [
  40. 'id' => 4,
  41. 'name' => 'change-'.uniqid(),
  42. 'message_type' => 1,
  43. 'message_content' => [
  44. ['text' => 'changexxxx']
  45. ],
  46. 'u_type' => 2,
  47. 'uc_unique_key' => uniqid('',true),
  48. 'send_at' => date('Y-m-d H:i:s', strtotime('+2 hour'))
  49. ]);
  50. $this->dumpJson($res);
  51. }
  52. public function testupdateGZH()
  53. {
  54. $res = $this->withHeaders([
  55. 'Authorization' => 'Bearer '. $this->token,
  56. ])->json('post','http://localhost/api/wechatPlatform/kfMessage/updateGZH', [
  57. 'id' => 2,
  58. 'gzh_ids' => [1,2,3]
  59. ]);
  60. $this->dumpJson($res);
  61. }
  62. public function teststop()
  63. {
  64. $res = $this->withHeaders([
  65. 'Authorization' => 'Bearer '. $this->token,
  66. ])->json('post','http://localhost/api/wechatPlatform/kfMessage/stop', [
  67. 'id' => 3
  68. ]);
  69. $this->dumpJson($res);
  70. }
  71. public function testdelete()
  72. {
  73. $res = $this->withHeaders([
  74. 'Authorization' => 'Bearer '. $this->token,
  75. ])->json('post','http://localhost/api/wechatPlatform/kfMessage/delete', [
  76. 'id' => 3
  77. ]);
  78. $this->dumpJson($res);
  79. }
  80. }