其他分享
首页 > 其他分享> > 对接航信开票-在线二维码开票

对接航信开票-在线二维码开票

作者:互联网

加密方式为 DES3  航信官方要求是DES加密方式,经和航信技术员沟通后 开放DES3加密方式。DES加密比较low了

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

<br>/**

     * 航信开票

     */

    public function HXInvoiceAction(){

        $oid empty($this->params["oid"]) ? '' $this->params["oid"];

        $OrdersData $this->model->getAny($oid);

        if($OrdersData['discount']){

            $discount = isset($OrdersData['discount'])?1:0;

            unset($OrdersData['discount']);

        }

        $Config = Config::getInstance();

        $webSite $Config->getWebSiteConfig();

        $code $webSite['HX_CODE'];

        $parameter = [];

        $details = [];

        $parameter['kptype'] = 1;

        $parameter['saletaxnum'] = $webSite['HX_DUTY'];                                             # 销方纳税人识别号  提供

        $parameter['saleaddress'] = $webSite['HX_SELLER_ADDRESS'];                                  # 销方地址  提供

        $parameter['salephone'] = $webSite['HX_SELLER_TEL'];                                        # 销方电话  提供

        $parameter['clerk'] = $webSite['HX_SELLER_CLERK'];                                          # 开票员   提供

        $parameter['orderno'] =  $code.$OrdersData[0]['orderNo'].'_'.strtotime($OrdersData[0]['createdt']);                                # orderno

        foreach ($OrdersData as $k=>$itm){

<br># 我这里为什么要余2 是因为我前端有特殊显示,所以再推送的时候多判断了一次。$discount = 有抵扣

            if($discount) {

                if ($k % 2 == 0) {

                    $parameter['invoicedate'] = $itm['createdt'];                                           # 订单日期

                    $parameter['ordertotal'] = $itm['paidPrice'];                                           # 价税合计金额    付款金额

                    $parameter['cpy'] = 0;                                                                  # 成品油标识

                    $details[$k]['goodsname'] = $itm['name'];                                               # 商品名称

                    $details[$k]['hsbz'] = 1;                                                               # 含税标志  表示单价、项目金额、折扣金额是否含税。0表示都不含税,1表示都含税   # 是否含税

                    $details[$k]['price'] = $itm['price2'];                                                 # 单价

//                    $details[$k]['spbm'] = isset($webSite['debug']) ? '1090511030000000000' : $itm['num'];      # 税收分类编码    提供

                    $details[$k]['spbm'] = $itm['num'];                                                     # 税收分类编码    提供

                    $details[$k]['num'] = $itm['qty2'];                                                     # 数量

                    $details[$k]['xmje'] = $itm['price2'] * $itm['qty2'];                                   # 小数点后2位,以元为单位精确到分。项目金额=单价*数量,根据含税标志,确定此金额是否含税

                    $details[$k]['se'] = '';                                                                # 税额 小数点后2位,以元为单位精确到分,当hsbz为0时,必填

                    $details[$k]['zkse'] = '';                                                              # 折扣税额

                    $details[$k]['zkje'] = $itm['zkje'];                                                    # 折扣金额

                    if ($itm['rate'] <= 0) {

                        if(substr($itm['num'],0,1) == 6){

                            $details[$k]['zzstsgl'] = "不征税";                                                           # 增值税特殊管理

                            $details[$k]['yhzcbs'] = "1";                                                           # 0:不使用;1:使用。默认为空,表示不使用

                        }

                        $details[$k]['lslbs'] = 2;                                                          # 零税率标识

                        $details[$k]['taxrate'] = 0;

                    else {

                        $details[$k]['zzstsgl'] = "";                                                           # 增值税特殊管理

                        $details[$k]['yhzcbs'] = "0";

                        $details[$k]['taxrate'] = $itm['rate'] / 100;                                       # 税率 用小数表示,如果税率为0,表示免税

                        $details[$k]['lslbs'] = '';

                    }

                }

            }else{

                $parameter['invoicedate'] = $itm['createdt'];

                $parameter['ordertotal'] = $itm['paidPrice'];

                $parameter['cpy'] = 0;

                $details[$k]['goodsname'] = $itm['name'];

                $details[$k]['hsbz'] = 1;

                $details[$k]['price'] = $itm['price2'];

                $details[$k]['spbm'] = $itm['num'];

                $details[$k]['num'] = $itm['qty2'];

                $details[$k]['yhzcbs'] = "0";

                $details[$k]['xmje'] = $itm['price2'] * $itm['qty2'];

                $details[$k]['se'] = '';

                $details[$k]['zkse'] = '';

                $details[$k]['zkje'] = '';

                $details[$k]['zzstsgl'] = "";

                if ($itm['rate'] <= 0) {

                    $details[$k]['lslbs'] = 1;

                    $details[$k]['taxrate'] = 0;

                else {

                    $details[$k]['taxrate'] = $itm['rate'] / 100;

                    $details[$k]['lslbs'] = '';

                }

            }

        }

        $parameter['detail'] = array_values($details);

        $parameter = json_encode($parameter,JSON_UNESCAPED_UNICODE);

//        var_dump($parameter);die;

        $s $this->des3_encrypt($parameter,$webSite['HX_SECRET_KRY']);

        $s $code.$s;

        $url $webSite['HX_URL'];

        $log new Logging();

        $log->lfile('HXpiao');

        $log->lwrite(' request:' $parameter );

        $log->lwrite(' request:' $s );

        $res $this->httpCurl($url,$s);

        $decrypt $this->des3_decrypted($res,$webSite['HX_SECRET_KRY']);

        $log->lwrite('decrypt:' $decrypt );

        $decrypt =  strstr($decrypt,'}',true).'}';  # 航信会携带一些字符回来  所以这里做下处理 然后转数组

        $decryptData = json_decode($decrypt,true);

        if($decryptData['status'] == 000){  # 成功后 为所欲为 航信会携带开票地址回来,解密后

            $_field array();

            $_field['HXResult'] = $decrypt;

            $_field['updatedt'] = 'now()';

            $where_fields array("AND" => array("=" => array('id' => $OrdersData[0]['id'], 'isdeleted' => 0)));

            $this->model->updateItem($_field$where_fields'orders');

        }

        echo $decrypt;

    }

<br><br><br>效果(不同税率有抵扣,不同税率无抵扣,不征税):

 

 

 

标签:webSite,OrdersData,HX,itm,开票,二维码,details,parameter,航信
来源: https://blog.csdn.net/jwx_abc6q6a/article/details/118720513