Test.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. namespace app\api\controller;
  3. use lk\Lk;
  4. use think\facade\Log;
  5. class Test
  6. {
  7. public function t1()
  8. {
  9. ajax_success();
  10. // $url = "https://lw_test.jinjianghc.com/api/sms/send";
  11. // $token = "oYtEwqzL68be506f50a52";
  12. $url = "http://bd.lwtest.com/api/sms/send";
  13. $token = "7ec987cb2daf4c44a84ff1f145c51f2b";
  14. $postArr = ['mobile'=>'13313826760','type'=>'lk','template_code'=>'verification_code','template_param'=>['code'=>'123123']];
  15. $postFields = json_encode($postArr);
  16. $ch = curl_init();
  17. curl_setopt($ch, CURLOPT_URL, $url);
  18. curl_setopt($ch, CURLOPT_HTTPHEADER, [
  19. 'Content-Type: application/json; charset=utf-8', //json版本需要填写 Content-Type: application/json;
  20. 'token:'.$token,
  21. ]
  22. );
  23. curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4); //若果报错 name lookup timed out 报错时添加这一行代码
  24. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  25. curl_setopt($ch, CURLOPT_POST, 1);
  26. curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields);
  27. curl_setopt($ch, CURLOPT_TIMEOUT, 60);
  28. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  29. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  30. $ret = curl_exec($ch);
  31. curl_close($ch);
  32. $rsp = json_decode($ret, true);
  33. halt($rsp);
  34. if ($rsp['code'] != 0) {
  35. Log::record('短信发送失败:' . json_encode($rsp) . "。原始参数:" . json_encode($postArr));
  36. return ['code' => 1, 'msg' => $rsp['errorMsg']];
  37. } else {
  38. return ['code' => 0];
  39. }
  40. }
  41. public function t2()
  42. {
  43. $filename = public_path().'取经条件.txt'; //文件路径
  44. header("Content-Type: application/octet-stream");
  45. header("Content-Disposition: attachment; filename=".basename($filename));
  46. readfile($filename);
  47. }
  48. public function t3()
  49. {
  50. $filename = public_path().'武器出处.txt'; //文件路径
  51. header("Content-Type: application/octet-stream");
  52. header("Content-Disposition: attachment; filename=".basename($filename));
  53. readfile($filename);
  54. }
  55. public function t4()
  56. {
  57. $filename = public_path().'武器装备属性.txt'; //文件路径
  58. header("Content-Type: application/octet-stream");
  59. header("Content-Disposition: attachment; filename=".basename($filename));
  60. readfile($filename);
  61. }
  62. }