Signature - ShenTengTu/node-tw-e-invoice GitHub Wiki
Signature
根據API規範,簽名在請求參數的
UTF-8
字符串中使用HMAC-SHA1
算法(APIKey
是秘密密鑰),並使用Base64
編碼產生結果。在簽名之前,請求參數需要按升序排序,而不是由URLEncode編碼,否則您將得到不正確的簽名。如果需要,簽名將自動生成。
According to the API spec, signature uses the HMAC-SHA1
algorithm on the UTF-8
string of the request parameter (APIKey
is the secret key) and uses Base64
encoding to produce the result.
Before signing,the request parameters need to be sorted in ascending order and not encoded by URLEncode, or you will get an incorrect signature.
Signature will auto generate if need :
require('dotenv').config();
const {TaiwanEInvoice, InquirerIdentity, CarrierCardType}= require('node-tw-e-invoice');
const {Serial}= require('node-tw-e-invoice').APIUtil;
const EInvoice = new TaiwanEInvoice(process.env.APP_ID,process.env.API_KEY);
const serial = new Serial();
EInvoice.inquirer(process.env.UUID,InquirerIdentity.Common)
.action('qryCarrierAgg',{
serial:serial.next(),
cardType: CarrierCardType.Mobile,
cardNo:'/AB56P5Q',
timeStamp:new Date(),
cardEncrypt:'password'
}).then((values)=>{
let {path,method,param} = values;
param.timeStamp += 10;
console.log(param.signature);//XxLFn6dBJPdOQ/d6GvqTvqSOn7w=
//start sending a request ...
}).catch((e)=>{console.log(e)});