Model_taxzhengzhou.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2. class Model_Taxzhengzhou extends Lin_Model
  3. {
  4. function __construct(){
  5. parent::__construct();
  6. $this->load->database();
  7. $this->table = 'taxzhengzhou';
  8. $this->load_table('tax_zhengzhou');
  9. }
  10. public function get_ht($ht)
  11. {
  12. return $this->find("ht = '$ht'");
  13. }
  14. public function get_orderno($orderno)
  15. {
  16. return $this->find("orderno = '$orderno'");
  17. }
  18. public function get_orders($data)
  19. {
  20. $xmend = "\n";
  21. //需要加密的报文
  22. $dataInfo = '<?xml version="1.0" encoding="UTF-8"?>'.$xmend;
  23. $dataInfo = '<order>'.$xmend;
  24. $dataInfo = '<orderHead>'.$xmend;
  25. $dataInfo = '<orderType>'.$data['ordertype'].'</orderType>'.$xmend;//电商平台的订单类型 I-进口商品订单;E-出口商品订单
  26. $dataInfo = '<tradeMode>'.$data['trademode'].'</tradeMode>'.$xmend;//一般出口填9610,特殊区域出口填1210
  27. $dataInfo = '<statisticsFlag>'.$data['statisticsflag'].'</statisticsFlag>'.$xmend;//A-简化申报.$xmend;B-汇总申报;
  28. $dataInfo = '<emsNo>'.$data['emsno'].'</emsNo>'.$xmend;//特殊区域出口模式必须填写具体账号(1210必填)。
  29. $dataInfo = '<orderNo>'.$data['orderno'].'</orderNo>'.$xmend;//电商平台的交易订单编号,同一平台的订单编号唯一不重复
  30. $dataInfo = '<ebpCode>'.$data['ebpcode'].'</ebpCode>'.$xmend;//电商平台的海关注册登记编号或统一社会信用代码。
  31. $dataInfo = '<logisticsCode>'.$data['logisticscode'].'</logisticsCode>'.$xmend;//物流企业的海关注册登记编号或统一社会信用代码。
  32. $dataInfo = '<iacCode>'.$data['iaccode'].'</iacCode>'.$xmend;//特殊区域内仓储企业的海关注册登记编号或统一社会信用代码,特殊区域出口模式必填
  33. $dataInfo = '<agentCode>'.$data['agentcode'].'</agentCode>'.$xmend;//代理申报企业编号
  34. $dataInfo = '<payCode>'.$data['paycode'].'</payCode>'.$xmend;//支付企业的海关编码,国内企业必填。
  35. $dataInfo = '<payName>'.$data['payname'].'</payName>'.$xmend;//支付企业名称,非线上支付填"现金支付"
  36. $dataInfo = '<ownerCode>'.$data['ownercode'].'</ownerCode>'.$xmend;//生产企业的海关注册登记编号或统一社会信用代码,未在海关登记的填NO
  37. $dataInfo = '<ownerName>'.$data['ownername'].'</ownerName>'.$xmend;//生产企业的登记名称
  38. $dataInfo = '<preNo>'.$data['preno'].'</preNo>'.$xmend;//电子口岸标识唯一编号(B+8位年月日+9位流水号)
  39. $dataInfo = '<licenseNo>'.$data['licenseno'].'</licenseNo>'.$xmend;//商务主管部门及其授权发证机关签发的进出口货物许可证的编号
  40. $dataInfo = '<portCode>'.$data['portcode'].'</portCode>'.$xmend;//商品实际出我国关境口岸海关的关区代码 JGS/T 18《海关关区代码》
  41. $dataInfo = '<ieDate>'.$data['iedate'].'</ieDate>'.$xmend;//时间格式:YYYYMMDD
  42. $dataInfo = '<batchNumber>'.$data['batchnumber'].'</batchNumber>'.$xmend;//商品批次号
  43. $dataInfo = '<wrapType>'.$data['wraptype'].'</wrapType>'.$xmend;//海关对进出口货物实际采用的外部包装方式的标识代码,采用1位数字表示,如:木箱、纸箱、桶装、散装、托盘、包、油罐车等
  44. $dataInfo = '<packNo>'.$data['packno'].'</packNo>'.$xmend;//件数(包裹数量)
  45. $dataInfo = '<grossWeight>'.$data['grossweight'].'</grossWeight>'.$xmend;//货物及其包装材料的重量之和,计量单位为千克
  46. $dataInfo = '<netWeight>'.$data['netweight'].'</netWeight>'.$xmend;//货物的毛重减去外包装材料后的重量,即货物本身的实际重量,计量单位为千克
  47. $dataInfo = '<goodsValue>'.$data['goodsvalue'].'</goodsValue>'.$xmend;//商品实际成交价FOB(不含运杂费),含非现金抵扣金额
  48. $dataInfo = '<discount>'.$data['discount'].'</discount>'.$xmend;//无则填写"0"
  49. $dataInfo = '<taxTotal>'.$data['taxtotal'].'</taxTotal>'.$xmend;//按照货款金额计算的税款,无法提供填写"0"
  50. $dataInfo = '<charge>'.$data['charge'].'</charge>'.$xmend;//支付企业的订单交易金额
  51. $dataInfo = '<freight>'.$data['freight'].'</freight>'.$xmend;//运杂费,无则填写"0"。
  52. $dataInfo = '<fFlag>'.$data['fflag'].'</fFlag>'.$xmend;//1-率,2-单价,3-总价
  53. $dataInfo = '<insuredFee>'.$data['insuredfee'].'</insuredFee>'.$xmend;//物流企业实际收取的商品保价费用
  54. $dataInfo = '<iFlag>'.$data['iflag'].'</iFlag>'.$xmend;//1-率,2-单价,3-总价
  55. $dataInfo = '<consigneeName>'.$data['consigneename'].'</consigneeName>'.$xmend;//收货人名称
  56. $dataInfo = '<consigneeTel>'.$data['consigneetel'].'</consigneeTel>'.$xmend;//收货人电话
  57. $dataInfo = '<consigneeAddress>'.$data['consigneeaddress'].'</consigneeAddress>'.$xmend;//收货人地址
  58. $dataInfo = '<trafMode>'.$data['trafmode'].'</trafMode>'.$xmend;//海关标准的参数代码 《JGS-20 海关业务代码集》- 运输方式代码
  59. $dataInfo = '<country>'.$data['country'].'</country>'.$xmend;//出口货物的直接运抵的国家(地区),《JGS-20 海关业务代码集》 国家(地区)代码表填写代码。
  60. $dataInfo = '<pod>'.$data['pod'].'</pod>'.$xmend;//出口运往境外的最终目的港的标识代码。最终目的港不可预知时,应尽可能按预知的目的港填报
  61. $dataInfo = '<logisticsNo>'.$data['logisticsno'].'</logisticsNo>'.$xmend;//物流企业运单的包裹面单号,同一物流企业的运单编号在6个月内不重复。
  62. $dataInfo = '<trafName>'.$data['trafname'].'</trafName>'.$xmend;//货物进出境的运输工具的名称或运输工具编号。填报内容应与运输部门向海关申报的载货清单所列相应内容一致。按照关区要求,可以后置申报清单总分单,允许为空。
  63. $dataInfo = '<voyageNo>'.$data['voyageno'].'</voyageNo>'.$xmend;//货物进出境的运输工具的航次编号。按照关区要求,可以后置申报清单总分单,允许为空。
  64. $dataInfo = '<billNo>'.$data['billno'].'</billNo>'.$xmend;//提单或总运单的编号。按照关区要求,可以后置申报清单总分单,允许为空。
  65. $dataInfo = '<totalPackageNo>'.$data['totalpackageno'].'</totalPackageNo>'.$xmend;//对于提运单下含有多个大包的托盘编号(邮件为邮件总包号/邮袋号)。按照关区要求,可以后置申报清单总分单,允许为空。
  66. $dataInfo = '<payNo>'.$data['payno'].'</payNo>'.$xmend;//支付交易编号
  67. $dataInfo = '<accountingDate>'.$data['accountingdate'].'</accountingDate>'.$xmend;//到账时间 格式:YYYYMMDDhhmmss
  68. $dataInfo = '<currencycus>'.$data['currencycus'].'</currencycus>'.$xmend;//海关标准的参数代码 《JGS-20 海关业务代码集》- 货币代码
  69. $dataInfo = '<currencyciq>'.$data['currencyciq'].'</currencyciq>'.$xmend;//币制编号,国检标准参数代码-币种
  70. $dataInfo = '<note>'.$data['note'].'</note>'.$xmend;
  71. $dataInfo = '</orderHead>'.$xmend;
  72. $dataInfo = '<orderList>'.$xmend;
  73. $dataInfo = '<gnum>'.$data['gnum'].'</gnum>'.$xmend;//从1开始的递增序号(与清单的商品项关联对应)
  74. $dataInfo = '<itemNo>'.$data['itemno'].'</itemNo>'.$xmend;//企业自定义的商品货号
  75. $dataInfo = '<itemRecordNo>'.$data['itemrecordno'].'</itemRecordNo>'.$xmend;//保税出口模式必填
  76. $dataInfo = '<itemName>'.$data['itemname'].'</itemName>'.$xmend;//同一类商品的中文名称。任何一种具体商品可以并只能归入表中的一个条目
  77. $dataInfo = '<gcode>'.$data['gcode'].'</gcode>'.$xmend;//对于符合简化申报的商品,前4位按税则归类申报(需要存在相应章节)
  78. $dataInfo = '<itemDescribe>'.$data['itemdescribe'].'</itemDescribe>'.$xmend;//电商平台上架的商品描述宣传信息
  79. $dataInfo = '<gmodel>'.$data['gmodel'].'</gmodel>'.$xmend;//满足海关归类、审价以及监管的要求为准。包括:品名、牌名、规格、型号、成份、含量、等级等
  80. $dataInfo = '<barCode>'.$data['barcode'].'</barCode>'.$xmend;//商品条形码一般由前缀部分、制造厂商代码、商品代码和校验码组成。没有条形码填“无”
  81. $dataInfo = '<qty>'.$data['qty'].'</qty>'.$xmend;
  82. $dataInfo = '<qty1>'.$data['qty1'].'</qty1>'.$xmend;
  83. $dataInfo = '<qty2>'.$data['qty2'].'</qty2>'.$xmend;
  84. $dataInfo = '<unitcus>'.$data['unitcus'].'</unitcus>'.$xmend;//海关标准的参数代码 《JGS-20 海关业务代码集》- 计量单位代码
  85. $dataInfo = '<unitciq>'.$data['unitciq'].'</unitciq>'.$xmend;//计量单位编号
  86. $dataInfo = '<unit1>'.$data['unit1'].'</unit1>'.$xmend;//海关标准的参数代码 《JGS-20 海关业务代码集》- 计量单位代码
  87. $dataInfo = '<unit2>'.$data['unit2'].'</unit2>'.$xmend;//海关标准的参数代码 《JGS-20 海关业务代码集》- 计量单位代码
  88. $dataInfo = '<price>'.$data['price'].'</price>'.$xmend;//成交单价FOB
  89. $dataInfo = '<totalPrice>'.$data['totalprice'].'</totalPrice>'.$xmend;//总价=成交数量*单价
  90. $dataInfo = '<currencycus>'.$data['currencycus'].'</currencycus>'.$xmend;//####海关标准的参数代码 海关标准的参数代码 《JGS-20 海关业务代码集》- 货币代码
  91. $dataInfo = '<country>'.$data['country'].'</country>'.$xmend;//#####海关标准的参数代码《JGS-20 海关业务代码集》 国家(地区)代码表填写代码。
  92. $dataInfo = '<note>'.$data['note'].'</note>'.$xmend;//#####
  93. $dataInfo = '</orderList>'.$xmend;
  94. $dataInfo = '</order>'.$xmend;
  95. $abs_path = './data/caiwu/rsa_public_key.key';
  96. $content = file_get_contents($abs_path);
  97. $key = openssl_pkey_get_public($content);
  98. openssl_public_encrypt($dataInfo,$encrypted,$key);
  99. $encrypted = base64_encode($encrypted);
  100. $byteArray = unpack('C*',$encrypted);
  101. //请求信息
  102. $xml = '<?xml version="1.0" encoding="UTF-8"?>'.$xmend;
  103. $xml .= '<root>'.$xmend;
  104. $xml .= '<pubInfo>'.$xmend;
  105. $xml .= '<version>'.$data['version'].'</version>'.$xmend;//Webservice接口版本2.0
  106. $xml .= '<companyCode>'.$data['companycode'].'</companyCode>'.$xmend;//电商企业的海关注册登记编号或统一社会信用代码
  107. $xml .= '<appType>'.$data['apptype'].'</appType>'.$xmend;//企业报送类型。1-新增 2-变更 3-删除。
  108. $xml .= '<appStatus>'.$data['appstatus'].'</appStatus>'.$xmend;//企业报送状态。1-暂存,2-申报。默认申报
  109. $xml .= '<signature>'.md5(implode('',$byteArray)).'</signature>'.$xmend;//验证加密报文是否一致
  110. $xml .= '<createTime>'.$data['createtime'].'</createTime>'.$xmend;//单据生成日期,格式:YYYYMMDDhhmmss。
  111. $xml .= '<customCode>'.$data['customcode'].'</customCode>'.$xmend;//关区代码(郑州保税区4611)
  112. $xml .= '</pubInfo>'.$xmend;
  113. $xml .= '<dataInfo>'.$encrypted.'</dataInfo>'.$xmend;//订单报文信息加密后内容
  114. $xml .= '</root>'.$xmend;
  115. $xml = 'xml='.$xml;
  116. $ch = curl_init();
  117. curl_setopt($ch, CURLOPT_URL,'http://emy.hnblc.com:9955/etouch-export/export/order/pushOrder');
  118. curl_setopt($ch, CURLOPT_POST, 1);
  119. curl_setopt($ch, CURLOPT_HEADER, 0);
  120. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  121. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  122. curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
  123. curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
  124. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  125. $data = curl_exec($ch);
  126. curl_close($ch);
  127. //$data = utf8_encode($data);
  128. libxml_disable_entity_loader(true);
  129. @$values = json_decode(json_encode(simplexml_load_string($data, 'SimpleXMLElement', LIBXML_NOCDATA)), true);
  130. return $values;
  131. }
  132. public function stringToByteArray($str,$charset) {
  133. $str = iconv($charset,'UTF-16',$str);
  134. preg_match_all('/(.)/s',$str,$bytes); //注:本文的盗版已经有了。不过,提示一下读者,这里的正则改了。
  135. $bytes=array_map('ord',$bytes[1]) ;
  136. return $bytes;
  137. }
  138. } //end class