You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
110 lines
3.6 KiB
110 lines
3.6 KiB
<?php
|
|
/**
|
|
* 发票管理服务
|
|
*/
|
|
|
|
namespace app\service\pay;
|
|
|
|
use app\model\Order;
|
|
use app\model\OrderGoodsDetail;
|
|
use app\model\OrderGoodsSource;
|
|
use app\model\User;
|
|
use app\service\BaseService;
|
|
use fast\Http;
|
|
use Firebase\JWT\JWT;
|
|
use Firebase\JWT\Key;
|
|
use think\facade\Db;
|
|
use app\service\pay\ApiHelperoneService;
|
|
use app\admin\controller\Base;
|
|
use think\facade\Cache;
|
|
|
|
class InvoiceManagementService extends BaseService
|
|
{
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
}
|
|
|
|
/**
|
|
* Notes: 发票申请接口
|
|
* User: torsenli
|
|
* Date: 2022/4/12
|
|
* Time: 18:04
|
|
*/
|
|
public function RespondToInvoices($data)
|
|
{
|
|
header('content-type:application/json;charset=utf8');
|
|
$openapiurl = "https://demo.szhtxx.cn:18182/apiv2/api/invoice/invoiceinfo/billing";
|
|
//请求数据
|
|
// $data = [
|
|
// 'buyerName' => '深圳亿起融网络科技有限公司', //购买方名称
|
|
// 'buyerType' => '01', //购买方类型01:企业
|
|
// 'buyerTaxNo' => '91440300326621149M', //购买方税号
|
|
// 'totalAmountTax' => '100.00', //总金额含税
|
|
// 'manualOrderDetails' => [[
|
|
// 'amount' => '100.00', //金额
|
|
// 'invoiceNature' => '0', //0:正常 1:折扣 2:被折扣
|
|
// 'itemName' => '山海经', //商品名称
|
|
// 'itemTaxCode' => '3049900000000000000', //商品税号
|
|
// 'taxIncluded' => '1', //1:含税0:不含税
|
|
// 'taxRate' => '0.06',//税率
|
|
// 'yhzcbs' => '0',//优惠政策标识
|
|
// ]],
|
|
// ];
|
|
$headers = array(
|
|
CURLOPT_HTTPHEADER => array(
|
|
'Content-Type:application/json;charset=UTF-8',
|
|
'Accept:application/json;charset=UTF-8',
|
|
'Authorization:bearer ' . $this->InvoiceRequestToken(),
|
|
'taxNo:440301999999980',
|
|
'machineNo:2',
|
|
),
|
|
);
|
|
|
|
$data = json_encode($data);
|
|
// $header = json_encode($header);
|
|
$aes = new security();
|
|
$httphelper = new HttpHelper();
|
|
// $result = $httphelper->send_post_info($openapiurl, $data, $header);
|
|
$result = Http::post($openapiurl, $data, $headers);
|
|
return json_decode($result['data'], true);
|
|
|
|
|
|
}
|
|
|
|
/**
|
|
* Notes:发票申请token
|
|
* User: torsenli
|
|
* Date: 2022/4/8
|
|
* Time: 18:05
|
|
*/
|
|
public function InvoiceRequestToken()
|
|
{
|
|
// header('content-type:application/json;charset=utf8');
|
|
header('content-type:application/json;charset=utf8');
|
|
$token = Cache::get('IRToken');
|
|
if (!$token) {
|
|
$openapiurl = "https://demo.szhtxx.cn:18182/apiv2/oauth/token";
|
|
|
|
$data = [
|
|
'client_id' => 'apiuser',
|
|
'client_secret' => 'secret',
|
|
'grant_type' => 'password',
|
|
'username' => '440301999999980',
|
|
'password' => '123456',
|
|
];
|
|
$aes = new security();
|
|
$httphelper = new HttpHelper();
|
|
$result = $httphelper->send_post($openapiurl, $data);
|
|
$val = json_decode($result, true);
|
|
|
|
Cache::set('IRToken', $val['access_token'], 3600);
|
|
return $val['access_token'];
|
|
} else {
|
|
return $token;
|
|
}
|
|
}
|
|
|
|
|
|
}
|