Apidsyskxcx.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. defined('BASEPATH') or exit('No direct script access allowed');
  3. /**
  4. * 此类是为了解决erp没有队列的问题,为了解决这个问题,先写一下这个类,避免后期写那么多定时任务类 这里只能解决每间隔多少时间执行一会的
  5. */
  6. class Apidsyskxcx extends Start_Controller
  7. {
  8. private $serect_str = "yskxcx";
  9. private $user_agent = 'Xcly251618/Yskxcx (Erp)';
  10. private $api = "Yskxcx25.424";
  11. private $ip = ['127.0.0.1','47.105.156.18'];
  12. public function __construct()
  13. {
  14. parent::__construct();
  15. $this->load->_model('Model_fullorder','fullorder');
  16. $this->load->_model("Model_logic_ding","logic_ding");
  17. $this->load->_model("Model_cne","cne");
  18. }
  19. public function _remap($arg, $arg_array)
  20. {
  21. $ip = $_SERVER['REMOTE_ADDR'];
  22. if(!in_array($ip,$this->ip)){
  23. exit("Unauthorized access");
  24. }
  25. $user_agent = empty($_SERVER['HTTP_USER_AGENT'])?"":$_SERVER['HTTP_USER_AGENT'];
  26. $token = empty($_SERVER['HTTP_X_AUTH_TOKEN'])?"":$_SERVER['HTTP_X_AUTH_TOKEN'];
  27. $time = $this->input->get('time',true);
  28. $api = $this->input->get('api',true);
  29. $this->checkAuth($user_agent,$token,$time,$api);
  30. if ($arg == 'jobs') //调出单
  31. {
  32. $this->_doRenwu();
  33. } else {
  34. $this->_index();
  35. }
  36. }
  37. /**
  38. * 校验是否有权限可以执行
  39. * $user_agent 自定义的请求客户端名称
  40. * $token 自定义的清华客户端的token
  41. * $time 请求的时间
  42. *
  43. */
  44. private function checkAuth($user_agent,$token,$time,$api){
  45. if($api != $this->api){
  46. exit("Access denied due to insufficient permissions");
  47. }
  48. $check_str = date("Ymd")."¥_".$this->serect_str."_¥".$time;
  49. if(empty($user_agent)){
  50. exit('No direct script access allowed');
  51. }
  52. if($user_agent != $this->user_agent){
  53. exit('Illegal request');
  54. }
  55. if(empty($token)){
  56. exit('No access permission');
  57. }
  58. $sercet_str = md5($check_str);
  59. if($sercet_str != $token){
  60. exit("Request permission is illegal");
  61. }
  62. }
  63. private function _index() {}
  64. private function _doRenwu(){
  65. //必须是云尚快线 打印
  66. $list = $this->fullorder->find_all("express = 71 and print = 3 and library = 2 and expressstate < 6");
  67. $waybill_list = array_column($list,'waybill');
  68. $split_waybills = array_chunk($waybill_list,10);
  69. //$this->logic_ding->sendToDing(json_encode($split_waybills));
  70. foreach($split_waybills as $v){
  71. $params =[];
  72. foreach($v as $item){
  73. $params[] = [
  74. "TrackNumber"=>$item,
  75. ];
  76. }
  77. }
  78. throw new Exception(json_encode($params));
  79. }
  80. }