UrlServiceTest.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Bear
  5. * Date: 2018/12/5
  6. * Time: 下午4:13
  7. */
  8. use app\main\service\UrlService;
  9. use think\Request;
  10. use app\main\model\object\ReturnObject;
  11. use app\main\constants\ErrorCodeConstants;
  12. use think\Cookie;
  13. class UrlServiceTest extends TestInit
  14. {
  15. /**
  16. * 行为测试之查询初始化
  17. */
  18. public function initActionWxSearch()
  19. {
  20. $request = $get = ["signature"=>"38764811537b387dbbf6ddd1f01fd8d8033f4b9a","timestamp"=>"1544001229","nonce"=>"1477657800","openid"=>"oKWvT0zCJH40HMT4ie4HlF7MoARQ","encrypt_type"=>"aes","msg_signature"=>"b7b4df5a61cb6e540bf0e6bf36b78198dc4f3e3c"];
  21. $server = ["USER"=>"www","HOME"=>"\/home\/www","HTTP_CONTENT_TYPE"=>"text\/xml","HTTP_PRAGMA"=>"no-cache","HTTP_ACCEPT"=>"*\/*","HTTP_USER_AGENT"=>"Mozilla\/4.0","HTTP_CONTENT_LENGTH"=>"534","HTTP_CONNECTION"=>"close","HTTP_VIA"=>"nginx","HTTP_X_FORWARDED_FOR"=>"140.207.54.75","HTTP_X_REAL_IP"=>"140.207.54.75","HTTP_HOST"=>"www.dev.kpread.com:80","REDIRECT_STATUS"=>"200","SERVER_NAME"=>"*.koread.cn","SERVER_PORT"=>"80","SERVER_ADDR"=>"192.168.0.104","REMOTE_PORT"=>"11176","REMOTE_ADDR"=>"192.168.0.181","SERVER_SOFTWARE"=>"nginx\/1.11.2","GATEWAY_INTERFACE"=>"CGI\/1.1","REQUEST_SCHEME"=>"http","SERVER_PROTOCOL"=>"HTTP\/1.0","DOCUMENT_ROOT"=>"\/var\/www\/cps\/public","DOCUMENT_URI"=>"\/index.php\/\/api\/wechat\/mpapi\/appid\/wx7610e3344bdea6f6","REQUEST_URI"=>"\/api\/wechat\/mpapi\/appid\/wx7610e3344bdea6f6?signature=38764811537b387dbbf6ddd1f01fd8d8033f4b9a&timestamp=1544001229&nonce=1477657800&openid=oKWvT0zCJH40HMT4ie4HlF7MoARQ&encrypt_type=aes&msg_signature=b7b4df5a61cb6e540bf0e6bf36b78198dc4f3e3c","SCRIPT_NAME"=>"\/index.php","CONTENT_LENGTH"=>"534","CONTENT_TYPE"=>"text\/xml","REQUEST_METHOD"=>"POST","QUERY_STRING"=>"signature=38764811537b387dbbf6ddd1f01fd8d8033f4b9a&timestamp=1544001229&nonce=1477657800&openid=oKWvT0zCJH40HMT4ie4HlF7MoARQ&encrypt_type=aes&msg_signature=b7b4df5a61cb6e540bf0e6bf36b78198dc4f3e3c","PATH_TRANSLATED"=>"\/var\/www\/cps\/public\/\/api\/wechat\/mpapi\/appid\/wx7610e3344bdea6f6","PATH_INFO"=>"\/\/api\/wechat\/mpapi\/appid\/wx7610e3344bdea6f6","SCRIPT_FILENAME"=>"\/var\/www\/cps\/public\/index.php","FCGI_ROLE"=>"RESPONDER","PHP_SELF"=>"\/index.php\/\/api\/wechat\/mpapi\/appid\/wx7610e3344bdea6f6","REQUEST_TIME_FLOAT"=>1544001229.646733,"REQUEST_TIME"=>1544001229];
  22. Request::instance()->get($get);
  23. Request::instance()->request($request);
  24. Request::instance()->server($server);
  25. }
  26. /**
  27. * 测试api.php中域名判断
  28. * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
  29. */
  30. public function testCheckApiDomain()
  31. {
  32. $this->initActionWxSearch();
  33. $result = UrlService::instance()->checkApiDomain();
  34. $this->assertInstanceOf(ReturnObject::class, $result);
  35. }
  36. /**
  37. * 获取支付域名,资源域名等
  38. */
  39. public function testGetSourceDomain()
  40. {
  41. $host = 'www.callback.dev.kpread.com';
  42. $expect = 'dev.kpread.com';
  43. $_SERVER['HTTP_HOST'] = $host;
  44. Request::instance()->server($_SERVER);
  45. $result = UrlService::instance()->getSourceDomain();
  46. $this->assertEquals($result, $expect);
  47. }
  48. /**
  49. * 测试www.dev.kpread.com是不是支付域名
  50. */
  51. public function testCheckDomainIsPay()
  52. {
  53. $this->initActionWxSearch();
  54. $result = UrlService::instance()->checkDomainIsPay();
  55. $this->assertFalse($result);
  56. }
  57. /**
  58. * 测试www.dev.kpread.com是不是入口域名
  59. */
  60. public function testCheckDomainIsEntry()
  61. {
  62. $this->initActionWxSearch();
  63. $result = UrlService::instance()->checkDomainIsEntry();
  64. $this->assertFalse($result);
  65. }
  66. /**
  67. * 测试www.dev.kpread.com是不是推广域名
  68. */
  69. public function testCheckDomainIsReferral()
  70. {
  71. $this->initActionWxSearch();
  72. $result = UrlService::instance()->checkDomainIsReferral();
  73. $this->assertFalse($result);
  74. }
  75. /**
  76. * 测试域名检测的返回值
  77. */
  78. public function testCheckFrontDomain()
  79. {
  80. $this->initActionWxSearch();
  81. $result = UrlService::instance()->checkFrontDomain();
  82. $this->assertInstanceOf(ReturnObject::class, $result);
  83. $this->assertTrue($result->code == ErrorCodeConstants::SUCCESS);
  84. }
  85. public function testGetUserReferralId()
  86. {
  87. $_COOKIE['user_id'] = '20000035';
  88. \app\main\service\UserService::instance()->getRunTimeObject()->urlType = \app\main\constants\OpenPlatformConstants::URL_TYPE_SPREAD;
  89. $data = UrlService::instance()->getUserReferralIdUpdate(774);
  90. var_dump($data);
  91. }
  92. }