StarifyTest.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. use Laravel\Lumen\Testing\DatabaseMigrations;
  3. use Laravel\Lumen\Testing\DatabaseTransactions;
  4. class StarifyTest extends TestCase
  5. {
  6. protected $token = '9fb69ef93b176ca394101d6231ec6358';
  7. /**
  8. * 测试模拟请求
  9. * @param string $method
  10. * @param string $url
  11. * @param array $params
  12. */
  13. public function request(string $method,string $url,array $params=[],$needToken=true){
  14. print_r(PHP_EOL.PHP_EOL.json_encode($params,JSON_UNESCAPED_UNICODE).PHP_EOL);
  15. if($needToken){
  16. $token=empty($this->token)?$this->getToken():$this->token;
  17. }else{
  18. $token='';
  19. }
  20. $headers = [
  21. 'X-Requested-With'=>'XMLHttpRequest',
  22. 'Content-Type' => 'application/x-www-form-urlencoded',
  23. 'token' => $token // AuthCheck的时候会进行刷新赋值
  24. ];
  25. $server = $this->transformHeadersToServerVars($headers);
  26. $response = $this->call($method,$url,$params,[], [], $server);
  27. print_r('HTTP状态码:'.$response->getStatusCode().PHP_EOL);
  28. print_r('返回值:'.PHP_EOL);
  29. $data = json_decode($response->getContent(),true);
  30. // $this->assertEquals(0,$data['ret']??-1);
  31. echo PHP_EOL.PHP_EOL.json_encode($data,JSON_UNESCAPED_UNICODE);
  32. return $data;
  33. }
  34. protected function getToken(){
  35. $response = $this->call('post','/api/app/login',['user_name'=>$this->username,'password'=>$this->password,'app_code'=>'JYGJ','app_key'=>'D0AB3EE73EDD8F70EB23E37231FCBC33']);
  36. if($response->getStatusCode()!=200){
  37. echo '登录失败';exit;
  38. }
  39. $data = json_decode($response->getContent(),true);
  40. if(!isset($data['code'])||isset($data['code']) && $data['code']!=0){
  41. print_r($data);
  42. exit;
  43. }
  44. return $data['data']['api_token'];
  45. }
  46. /**
  47. * 获取用户列表
  48. * */
  49. public function testStarifyUserList(){
  50. $data=[];
  51. $this->request('get','/api/admin/user-list?page=1&page_size=10&keyword=',$data);
  52. }
  53. /**
  54. * 获取用户列表
  55. * */
  56. public function testWaCloudBillList(){
  57. $data=[];
  58. $this->request('get','/api/admin/wa-cloud-bill-list?date=&user_id=1000090&page=1&page_size=10&keyword=',$data);
  59. }
  60. /**
  61. * 保存星光用户充值记录
  62. * */
  63. public function testSaveStarifyWaCloudBill(){
  64. $data=[];
  65. $data['amount']=100;
  66. $data['type']=1;
  67. $data['id']=0;
  68. $data['user_id']=1000090;
  69. $this->request('post','/api/admin/wa-cloud-bill-save',$data);
  70. }
  71. }