123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- <?php
- /**
- * Created by PhpStorm.
- * User: Bear
- * Date: 2018/12/5
- * Time: 下午4:13
- */
- use app\main\service\UrlService;
- use think\Request;
- use app\main\model\object\ReturnObject;
- use app\main\constants\ErrorCodeConstants;
- use think\Cookie;
- class UrlServiceTest extends TestInit
- {
- /**
- * 行为测试之查询初始化
- */
- public function initActionWxSearch()
- {
- $request = $get = ["signature"=>"38764811537b387dbbf6ddd1f01fd8d8033f4b9a","timestamp"=>"1544001229","nonce"=>"1477657800","openid"=>"oKWvT0zCJH40HMT4ie4HlF7MoARQ","encrypt_type"=>"aes","msg_signature"=>"b7b4df5a61cb6e540bf0e6bf36b78198dc4f3e3c"];
- $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×tamp=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×tamp=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];
- Request::instance()->get($get);
- Request::instance()->request($request);
- Request::instance()->server($server);
- }
- /**
- * 测试api.php中域名判断
- * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
- */
- public function testCheckApiDomain()
- {
- $this->initActionWxSearch();
- $result = UrlService::instance()->checkApiDomain();
- $this->assertInstanceOf(ReturnObject::class, $result);
- }
- /**
- * 获取支付域名,资源域名等
- */
- public function testGetSourceDomain()
- {
- $host = 'www.callback.dev.kpread.com';
- $expect = 'dev.kpread.com';
- $_SERVER['HTTP_HOST'] = $host;
- Request::instance()->server($_SERVER);
- $result = UrlService::instance()->getSourceDomain();
- $this->assertEquals($result, $expect);
- }
- /**
- * 测试www.dev.kpread.com是不是支付域名
- */
- public function testCheckDomainIsPay()
- {
- $this->initActionWxSearch();
- $result = UrlService::instance()->checkDomainIsPay();
- $this->assertFalse($result);
- }
- /**
- * 测试www.dev.kpread.com是不是入口域名
- */
- public function testCheckDomainIsEntry()
- {
- $this->initActionWxSearch();
- $result = UrlService::instance()->checkDomainIsEntry();
- $this->assertFalse($result);
- }
- /**
- * 测试www.dev.kpread.com是不是推广域名
- */
- public function testCheckDomainIsReferral()
- {
- $this->initActionWxSearch();
- $result = UrlService::instance()->checkDomainIsReferral();
- $this->assertFalse($result);
- }
- /**
- * 测试域名检测的返回值
- */
- public function testCheckFrontDomain()
- {
- $this->initActionWxSearch();
- $result = UrlService::instance()->checkFrontDomain();
- $this->assertInstanceOf(ReturnObject::class, $result);
- $this->assertTrue($result->code == ErrorCodeConstants::SUCCESS);
- }
- public function testGetUserReferralId()
- {
- $_COOKIE['user_id'] = '20000035';
- \app\main\service\UserService::instance()->getRunTimeObject()->urlType = \app\main\constants\OpenPlatformConstants::URL_TYPE_SPREAD;
- $data = UrlService::instance()->getUserReferralIdUpdate(774);
- var_dump($data);
- }
- }
|