ExpresscfKdnConfig.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <?php
  2. namespace app\common\model;
  3. use think\facade\Db;
  4. /**
  5. * ============================================================================
  6. * DSKMS多用户商城
  7. * ============================================================================
  8. * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
  9. * 网站地址: http://www.csdeshang.com
  10. * ----------------------------------------------------------------------------
  11. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
  12. * 不允许对程序代码以任何形式任何目的的再发布。
  13. * ============================================================================
  14. * 数据层模型
  15. */
  16. class ExpresscfKdnConfig extends BaseModel {
  17. public $page_info;
  18. public function getExpresscfKdnConfigList($condition, $field = '*', $pagesize = 10, $order = 'expresscf_kdn_config_id desc') {
  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. $result = Db::name('expresscf_kdn_config')->where($condition)->find();
  37. return $result;
  38. }
  39. /**
  40. * 新增
  41. * @access public
  42. * @author csdeshang
  43. * @param array $data 参数内容
  44. * @return bool 布尔类型的返回结果
  45. */
  46. public function addExpresscfKdnConfig($data) {
  47. $result = Db::name('expresscf_kdn_config')->insertGetId($data);
  48. return $result;
  49. }
  50. /**
  51. * 更新信息
  52. * @access public
  53. * @author csdeshang
  54. * @param array $data 数据
  55. * @param array $condition 条件
  56. * @return bool
  57. */
  58. public function editExpresscfKdnConfig($data, $condition) {
  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. return Db::name('expresscf_kdn_config')->where($condition)->delete();
  71. }
  72. public function requestExpresscfKdnApi($requestData, $RequestType, $EBusinessID, $ApiKey) {
  73. $requestData = json_encode($requestData, JSON_UNESCAPED_UNICODE);
  74. // 组装系统级参数
  75. $datas = array(
  76. 'EBusinessID' => $EBusinessID,
  77. 'RequestType' => $RequestType,
  78. 'RequestData' => urlencode($requestData),
  79. 'DataType' => '2',
  80. );
  81. $datas['DataSign'] = urlencode(base64_encode(md5($requestData . $ApiKey)));
  82. //以form表单形式提交post请求,post请求体中包含了应用级参数和系统级参数
  83. $result = http_request('https://api.kdniao.com/api/EOrderService', 'POST', $datas);
  84. $result = json_decode($result, true);
  85. //根据公司业务处理返回的信息......
  86. return $result;
  87. }
  88. public function printExpresscfKdnOrder($requestData, $EBusinessID, $ApiKey) {
  89. $requestData = json_encode($requestData, JSON_UNESCAPED_UNICODE);
  90. $data_sign = urlencode(base64_encode(md5($this->get_ip() . $requestData . $ApiKey)));
  91. //是否预览,0-不预览 1-预览
  92. $is_priview = '0';
  93. //组装表单
  94. $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>';
  95. return $form;
  96. }
  97. /**
  98. * 判断是否为内网IP
  99. * @param ip IP
  100. * @return 是否内网IP
  101. */
  102. private function is_private_ip($ip) {
  103. return !filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE);
  104. }
  105. /**
  106. * 获取客户端IP(非用户服务器IP)
  107. * @return 客户端IP
  108. */
  109. private function get_ip() {
  110. //获取客户端IP
  111. if (getenv('HTTP_CLIENT_IP') && strcasecmp(getenv('HTTP_CLIENT_IP'), 'unknown')) {
  112. $ip = getenv('HTTP_CLIENT_IP');
  113. } elseif (getenv('HTTP_X_FORWARDED_FOR') && strcasecmp(getenv('HTTP_X_FORWARDED_FOR'), 'unknown')) {
  114. $ip = getenv('HTTP_X_FORWARDED_FOR');
  115. } elseif (getenv('REMOTE_ADDR') && strcasecmp(getenv('REMOTE_ADDR'), 'unknown')) {
  116. $ip = getenv('REMOTE_ADDR');
  117. } elseif (isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], 'unknown')) {
  118. $ip = $_SERVER['REMOTE_ADDR'];
  119. }
  120. $ip = strstr($ip, '<!DOCTYPE html>', true);
  121. $ip = trim($ip);
  122. if (!$ip || $this->is_private_ip($ip)) {
  123. $ch = curl_init();
  124. curl_setopt($ch, CURLOPT_URL, 'https://www.kdniao.com/External/GetIp.aspx');
  125. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  126. $output = curl_exec($ch);
  127. return $output;
  128. } else {
  129. return $ip;
  130. }
  131. }
  132. }