ExpresscfKdnConfig.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <?php
  2. namespace app\common\model;
  3. use think\facade\Db;
  4. /**
  5. * DSKMS多用户商城
  6. *
  7. * ----------------------------------------------------------------------------
  8. *
  9. * 数据层模型
  10. */
  11. class ExpresscfKdnConfig extends BaseModel
  12. {
  13. public $page_info;
  14. public function getExpresscfKdnConfigList($condition, $field = '*', $pagesize = 10, $order = 'expresscf_kdn_config_id desc')
  15. {
  16. if ($pagesize) {
  17. $result = Db::name('expresscf_kdn_config')->field($field)->where($condition)->order($order)->paginate(['list_rows' => $pagesize, 'query' => request()->param()], false);
  18. $this->page_info = $result;
  19. return $result->items();
  20. } else {
  21. $result = Db::name('expresscf_kdn_config')->field($field)->where($condition)->order($order)->select()->toArray();
  22. return $result;
  23. }
  24. }
  25. /**
  26. * 取单个内容
  27. * @access public
  28. * @author csdeshang
  29. * @param int $id 分类ID
  30. * @return array 数组类型的返回结果
  31. */
  32. public function getExpresscfKdnConfigInfo($condition)
  33. {
  34. $result = Db::name('expresscf_kdn_config')->where($condition)->find();
  35. return $result;
  36. }
  37. /**
  38. * 新增
  39. * @access public
  40. * @author csdeshang
  41. * @param array $data 参数内容
  42. * @return bool 布尔类型的返回结果
  43. */
  44. public function addExpresscfKdnConfig($data)
  45. {
  46. $result = Db::name('expresscf_kdn_config')->insertGetId($data);
  47. return $result;
  48. }
  49. /**
  50. * 更新信息
  51. * @access public
  52. * @author csdeshang
  53. * @param array $data 数据
  54. * @param array $condition 条件
  55. * @return bool
  56. */
  57. public function editExpresscfKdnConfig($data, $condition)
  58. {
  59. $result = Db::name('expresscf_kdn_config')->where($condition)->update($data);
  60. return $result;
  61. }
  62. /**
  63. * 删除分类
  64. * @access public
  65. * @author csdeshang
  66. * @param int $condition 记录ID
  67. * @return bool
  68. */
  69. public function delExpresscfKdnConfig($condition)
  70. {
  71. return Db::name('expresscf_kdn_config')->where($condition)->delete();
  72. }
  73. public function requestExpresscfKdnApi($requestData, $RequestType, $EBusinessID, $ApiKey)
  74. {
  75. $requestData = json_encode($requestData, JSON_UNESCAPED_UNICODE);
  76. // 组装系统级参数
  77. $datas = array(
  78. 'EBusinessID' => $EBusinessID,
  79. 'RequestType' => $RequestType,
  80. 'RequestData' => urlencode($requestData),
  81. 'DataType' => '2',
  82. );
  83. $datas['DataSign'] = urlencode(base64_encode(md5($requestData . $ApiKey)));
  84. //以form表单形式提交post请求,post请求体中包含了应用级参数和系统级参数
  85. $result = http_request('https://api.kdniao.com/api/EOrderService', 'POST', $datas);
  86. $result = json_decode($result, true);
  87. //根据公司业务处理返回的信息......
  88. return $result;
  89. }
  90. public function printExpresscfKdnOrder($requestData, $EBusinessID, $ApiKey)
  91. {
  92. $requestData = json_encode($requestData, JSON_UNESCAPED_UNICODE);
  93. $data_sign = urlencode(base64_encode(md5($this->get_ip() . $requestData . $ApiKey)));
  94. //是否预览,0-不预览 1-预览
  95. $is_priview = '0';
  96. //组装表单
  97. $form = '<form id="form1" method="POST" action="' . 'https://www.kdniao.com/External/PrintOrder.aspx' . '"><input type="text" name="RequestData" value=\'' . $requestData . '\'/><input type="text" name="EBusinessID" value="' . $EBusinessID . '"/><input type="text" name="DataSign" value="' . $data_sign . '"/><input type="text" name="IsPriview" value="' . $is_priview . '"/></form><script>form1.submit();</script>';
  98. return $form;
  99. }
  100. /**
  101. * 判断是否为内网IP
  102. * @param ip IP
  103. * @return 是否内网IP
  104. */
  105. private function is_private_ip($ip)
  106. {
  107. return !filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE);
  108. }
  109. /**
  110. * 获取客户端IP(非用户服务器IP)
  111. * @return 客户端IP
  112. */
  113. private function get_ip()
  114. {
  115. //获取客户端IP
  116. if (getenv('HTTP_CLIENT_IP') && strcasecmp(getenv('HTTP_CLIENT_IP'), 'unknown')) {
  117. $ip = getenv('HTTP_CLIENT_IP');
  118. } elseif (getenv('HTTP_X_FORWARDED_FOR') && strcasecmp(getenv('HTTP_X_FORWARDED_FOR'), 'unknown')) {
  119. $ip = getenv('HTTP_X_FORWARDED_FOR');
  120. } elseif (getenv('REMOTE_ADDR') && strcasecmp(getenv('REMOTE_ADDR'), 'unknown')) {
  121. $ip = getenv('REMOTE_ADDR');
  122. } elseif (isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], 'unknown')) {
  123. $ip = $_SERVER['REMOTE_ADDR'];
  124. }
  125. $ip = strstr($ip, '<!DOCTYPE html>', true);
  126. $ip = trim($ip);
  127. if (!$ip || $this->is_private_ip($ip)) {
  128. $ch = curl_init();
  129. curl_setopt($ch, CURLOPT_URL, 'https://www.kdniao.com/External/GetIp.aspx');
  130. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  131. $output = curl_exec($ch);
  132. return $output;
  133. } else {
  134. return $ip;
  135. }
  136. }
  137. }