ExpresscfKdnConfig.php 5.5 KB

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