ExpresscfKdnConfig.php 5.6 KB

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