Postman测试sanic接口详解(带签名验证)

2020年9月25日 09:45 by wst

web开发

问题:

当测试带签名的sanic接口时,因为要生成签名,都是用代码测试的。

麻烦的地方在于,还要写测试代码。postman不能生成签名吗?

解决方案:

经过搜索,发现postman是可以生成签名的。脚本可以写在Pre-request Script里。如图:

签名的验证是通过header中的timestamp和token字段进行验证的。

完整的代码如下:


//签名Key
const SIGN_KEY = "xxxxxxxxxx";

// GET请求生成签名
function gen_get_sign(timestamp) {
    // 获取GET参数
    query_params = pm.request.url.query.all();
    // 根据key值升序排列
    query_params.sort(function(obj1,obj2) {
        var value1 = obj1['key'];
        var value2 = obj2['key'];
        if (value1 < value2 ) {
            return -1; 
        } else if (value1 > value2 ) { 
            return 1; 
        } else { 
            return 0; 
        }});
    // 拼接签名字符串
    let sign_text = "";
    for (let param of query_params){
        sign_text += (param["key"]+ "="+param["value"]+"&");
    }
    sign_text += ("timestamp=" + timestamp + "&" + SIGN_KEY);
    // 生成签名
    sign = CryptoJS.MD5(sign_text).toString();
    return sign;
}

// POST 请求生成签名
function gen_post_sign(timestamp) {
    requst_body = pm.request.body;
    sign_text = "";
    if(!requst_body.isEmpty() && pm.request.body.mode == "raw"){
        sign_text = requst_body;
    }
    sign_text += ("&timestamp=" + timestamp + "&" + SIGN_KEY);
    sign = CryptoJS.MD5(sign_text).toString();
    return sign;
}

//生成时间戳
let timestamp = Math.floor(+new Date() / 1000);

// 生成签名
let token = ""
if(pm.request.method=='POST') {
    token = gen_post_sign(timestamp);
} else if(pm.request.method=='GET') {
    token = gen_get_sign(timestamp)
} else {
    console.log("没找到["+ pm.request.method + "]请求方式的签名算法")
}

//设置请求头,添加时间戳和签名
pm.request.headers.add({
    key: "timestamp",
    value: timestamp
})
pm.request.headers.add({
    key: "token",
    value: token
})

 

如有其他问题,请留言!


Comments(130) Add Your Comment

Charlesnag
“I haven’t seen you in these parts,” the barkeep said, sidling over to where I sat. “Personage’s Bao.” He stated it exuberantly, as if solemn word of honour of his exploits were shared by means of settlers hither multifarious a verve in Aeternum. He waved to a expressionless keg apart from us, and I returned his gesture with a nod. He filled a field-glasses and slid it to me across the stained red wood of the court before continuing. “As a betting houseman, I’d be ready to wager a adequate piece of invent you’re in Ebonscale Reach on the side of more than the wet one's whistle and sights,” he said, eyes glancing from the sword sheathed on my cool to the bend slung across my back. http://www.google.com.mt/url?q=https://renewworld.ru/new-world-kak-popast-na-alfa-i-beta-testy/
Kevingaw
https://sonnenreiter.de/wp-includes/pgs/?welches_online_casino_ist_zu_empfehlen_3.html https://kommstdu-hierher.de/wp-includes/inc/welches_casino_spielt_knossi_.html https://maps.google.ge/url?q=http://tanzschule-schrittfest.de/wp-content/pages/welche_online_casinos_sind_in_deutschland_legal__2.html http://tanzschule-schrittfest.de/wp-content/pages/welche_online_casinos_sind_in_deutschland_legal__2.html http://maps.google.is/url?q=http://www.unihockey.ch/images/pages/die_besten_casinos_und_hotels_in_las_vegas__nevada__usa_und_wie_viele_es_dort_gibt.html
Kevingaw
https://www.merkur-zeitschrift.de/wp-content/pages/die_besten_casinos_in_las_vegas_auf_dem_strip.html https://www.google.gr/url?sa=i&rct=j&q=&esrc=s&source=images&cd=&cad=rja&uact=8&ved=2ahUKEwilpIir-vHaAhXDCuwKHdDbC8IQjRx6BAgBEAU&url=http://cloudbetwelcomebonus.com/it/ https://images.google.com.my/url?q=http://cloudbetwelcomebonus.com/de/ https://images.google.iq/url?q=https://1xbitapk.com/tr/ http://pinup-fashion.de/wp-content/pages/welche_online_casinos_sind_in_deutschland_legal_.html
Sbwvto
buy lipitor pills for sale <a href="https://lipiws.top/">generic lipitor 10mg</a> order atorvastatin 40mg pills
Okhnpk
ciprofloxacin 1000mg price - <a href="https://cipropro.top/">buy generic cipro 500mg</a> augmentin 625mg brand
Bclcmr
where to buy cipro without a prescription - <a href="https://metroagyl.top/azithromycin/">buy augmentin tablets</a> buy augmentin 375mg pills
Zyfyud
buy ciplox 500 mg for sale - <a href="https://septrim.top/trimox/">buy generic amoxicillin 500mg</a> buy erythromycin pills for sale
Yzxaqr
flagyl pills - <a href="https://metroagyl.top/cefaclor/">order cefaclor capsules</a> azithromycin for sale
Prekoz
buy oral ivermectin - <a href="https://keflexin.top/">how to get ciplox without a prescription</a> generic tetracycline 250mg
Lbtwfe
purchase valacyclovir online - <a href="https://gnantiviralp.com/">valtrex pills</a> zovirax sale
Ivzkko
buy cheap generic acillin <a href="https://ampiacil.top/penicillinused/">purchase penicillin without prescription</a> amoxicillin pills
Nbdrhm
order flagyl 200mg online cheap - <a href="https://metroagyl.top/oxytetracycline/">oxytetracycline cheap</a> azithromycin price
Hywshd
order furosemide for sale - <a href="https://antipathogenc.com/medex/">warfarin 2mg pills</a> buy capoten 25mg generic
Asnwpc
order glucophage sale - <a href="https://gnantiacidity.com/septra/">order generic bactrim</a> buy lincomycin 500 mg generic
Jjhcmw
purchase retrovir pills - <a href="https://canadiangnp.com/">glucophage cost</a> generic allopurinol
Kxhpbs
clozaril over the counter - <a href="https://genonlinep.com/coversyl/">order perindopril 4mg</a> order pepcid 40mg sale
Agglon
buy generic clomipramine over the counter - <a href="https://antdeponline.com/">anafranil oral</a> sinequan 75mg price
Dzhngq
order seroquel 50mg without prescription - <a href="https://gnkantdepres.com/effexor/">cheap effexor 150mg</a> eskalith pill
Mfrhee
atarax cost - <a href="https://antdepls.com/pamelor/">cheap nortriptyline</a> order amitriptyline 10mg
Ekchhn
buy augmentin without a prescription - <a href="https://atbioinfo.com/linezolid/">order generic linezolid 600 mg</a> cipro cheap
Oakxpd
amoxicillin uk - <a href="https://atbioxotc.com/ceftin/">buy generic axetil online</a> order ciprofloxacin 500mg for sale
Comdxt
buy azithromycin medication - <a href="https://gncatbp.com/btetracycline/">generic sumycin</a> buy generic ciplox for sale
Nblscw
purchase cleocin online - <a href="https://cadbiot.com/oxytetracycline/">terramycin 250mg generic</a> chloromycetin buy online
Fvrvxo
buy ivermectin 12 mg online - <a href="https://antibpl.com/tylquin/">order levofloxacin for sale</a> order generic cefaclor 500mg
Odfbzg
generic ventolin 2mg - <a href="https://antxallergic.com/oiphenergan/">promethazine order online</a> order theo-24 Cr 400mg generic
Gqupop
depo-medrol pills - <a href="https://ntallegpl.com/getazelastine/">order astelin 10 ml online cheap</a> astelin buy online
Gatlve
desloratadine drug - <a href="https://rxtallerg.com/getaristocort/">order triamcinolone 4mg generic</a> order generic albuterol
Qyebyk
micronase 5mg tablet - <a href="https://prodeprpl.com/pioglitazone30/">cheap pioglitazone 15mg</a> buy forxiga generic
Isbkwn
glycomet cost - <a href="https://arxdepress.com/sitagliptin50/">buy sitagliptin 100mg online</a> purchase precose online
Wympoe
order repaglinide online - <a href="https://depressinfo.com/">prandin pills</a> jardiance 25mg price
Dpgddz
brand rybelsus - <a href="https://infodeppl.com/">buy semaglutide medication</a> brand desmopressin
Aqfbtr
order lamisil generic - <a href="https://treatfungusx.com/xgrifulvinvs/">grifulvin v medication</a> purchase griseofulvin online cheap
Atbfpu
purchase nizoral for sale - <a href="https://antifungusrp.com/itraconazole100/">sporanox online buy</a> buy sporanox 100 mg without prescription
Tmdick
purchase famvir pill - <a href="https://amvinherpes.com/gnvalaciclovir/">buy valaciclovir 500mg</a> valcivir uk
Jopixz
cheap digoxin 250 mg - <a href="https://blpressureok.com/isoptinpillmg/">buy calan 240mg generic</a> lasix buy online
Drcrqu
oral lopressor 100mg - <a href="https://bloodpresspl.com/telmisartan/">cost micardis 80mg</a> cheap nifedipine 30mg
Slbuna
order hydrochlorothiazide 25 mg generic - <a href="https://norvapril.com/lisinopril/">order lisinopril 5mg online cheap</a> bisoprolol pill
Biaqlw
nitroglycerin order - <a href="https://nitroproxl.com/valsartan/">purchase valsartan sale</a> valsartan 80mg over the counter
Rutpok
simvastatin dungeon - <a href="https://canescholest.com/fenofibrate/">fenofibrate dreadful</a> atorvastatin since
Doeflg
rosuvastatin pills truth - <a href="https://antcholesterol.com/ezetimibe/">ezetimibe stand</a> caduet pills ponder
Idrllh
viagra professional online born - <a href="https://edsildps.com/superavana/">super avana instance</a> levitra oral jelly hat
Beflxu
dapoxetine sparkler - <a href="https://promedprili.com/zudena/">udenafil wonder</a> cialis with dapoxetine glow
Xfwujv
cenforce online deck - <a href="https://xcenforcem.com/cialistadalafil/">cialis price</a> brand viagra pills bench
Pqhcyn
brand cialis atmosphere - <a href="https://probrandtad.com/forzestpills/">forzest winter</a> penisole yesterday
Visdif
brand cialis number - <a href="https://probrandtad.com/zhewitra/">zhewitra year</a> penisole castle
Fhsfsb
cialis soft tabs shin - <a href="https://supervalip.com/viagraoraljelly/">viagra oral jelly liberty</a> viagra oral jelly hot
Fqwjud
cialis soft tabs conduct - <a href="https://supervalip.com/">cialis soft tabs pills stock</a> viagra oral jelly shell
Clfuya
dapoxetine edge - <a href="https://promedprili.com/cialiswithdapoxetine/">cialis with dapoxetine disease</a> cialis with dapoxetine win
Mgkugv
cenforce tray - <a href="https://xcenforcem.com/tadalissxtadalafil/">tadalis property</a> brand viagra pills hint
Svvvah
asthma treatment sweet - <a href="https://bsasthmaps.com/">asthma treatment fight</a> asthma medication pardon
Yhntjt
acne medication audience - <a href="https://placnemedx.com/">acne medication argue</a> acne treatment thief
Xufrcc
prostatitis pills plunge - <a href="https://xprosttreat.com/">prostatitis medications consider</a> pills for treat prostatitis anger
Rvlrdg
treatment for uti local - <a href="https://amenahealthp.com/">treatment for uti direction</a> treatment for uti faint
Vobuuv
loratadine medication hollow - <a href="https://clatadine.top/">loratadine medication score</a> claritin tend
Dvqcmo
valtrex online snarl - <a href="https://gnantiviralp.com/">valtrex temper</a> valtrex online use
Hlyhhw
priligy exchange - <a href="https://prilixgn.top/">priligy quiver</a> dapoxetine duty
Edcypv
claritin pills excitement - <a href="https://clatadine.top/">claritin idiot</a> claritin pills card
Ybiokt
ascorbic acid design - <a href="https://ascxacid.com/">ascorbic acid consideration</a> ascorbic acid style
Mbrcqs
promethazine dismiss - <a href="https://prohnrg.com/">promethazine disgust</a> promethazine many
Kxfivp
clarithromycin pills sixty - <a href="https://gastropls.com/gncytotec/">cytotec pills bat</a> cytotec pills sweat
Buldfx
florinef pills fully - <a href="https://gastroplusp.com/nexesomeprazole/">nexium little</a> lansoprazole pills yourself
Usutop
order rabeprazole sale - <a href="https://gastrointesl.com/">rabeprazole generic</a> order motilium 10mg sale
Acqdts
bisacodyl uk - <a href="https://gastroinfop.com/">buy bisacodyl without a prescription</a> buy liv52 20mg generic
Lmcrbx
buy cheap generic zovirax - <a href="https://danaterone.shop/">order generic hydroquinone</a> duphaston 10mg price
Jcsiku
buy bactrim 960mg without prescription - <a href="https://ketiracet.com/">order keppra 1000mg for sale</a> order tobra
Tfiwaf
how to get griseofulvin without a prescription - <a href="https://fulviseoful.com/">brand fulvicin</a> order lopid 300mg online cheap
Nimfpk
order dapagliflozin without prescription - <a href="https://precarbos.com/">acarbose 25mg for sale</a> acarbose 50mg over the counter
Togbwk
dramamine us - <a href="https://actodronate.com/">actonel 35mg uk</a> actonel medication
Upxsrk
vasotec 10mg pills - <a href="https://doxapisin.com/">brand doxazosin</a> xalatan online
Tvoqej
monograph 600mg for sale - <a href="https://etodograph.com/">buy generic etodolac</a> pletal 100mg price
Zjikmq
piroxicam over the counter - <a href="https://feldexicam.com/">where can i buy feldene</a> exelon 3mg tablet
Xjuegk
buy generic piracetam over the counter - <a href="https://nootquin.com/levofloxacin/">levofloxacin canada</a> sinemet order online
Dmbfvw
buy hydrea pill - <a href="https://hydroydrinfo.com/methocarbamol/">methocarbamol uk</a> buy methocarbamol 500mg generic
Cjzewi
order divalproex 500mg generic - <a href="https://adepamox.com/mefloquine/">mefloquine pills</a> buy topamax 100mg sale
Nrysig
order norpace generic - <a href="https://anorpica.com/">cheap norpace generic</a> thorazine sale
Vqonrx
purchase spironolactone pills - <a href="https://aldantinep.com/naltrexone/">buy naltrexone 50mg generic</a> purchase revia pills
Gqbjwj
cyclophosphamide canada - <a href="https://cycloxalp.com/stavudine/">cheap stavudine tablets</a> purchase trimetazidine online
Sfnnay
order flexeril 15mg for sale - <a href="https://abflequine.com/olanzapine/">generic olanzapine 10mg</a> order vasotec without prescription
Hiwjfz
zofran generic - <a href="https://azofarininfo.com/ropinirole/">generic ropinirole 1mg</a> order ropinirole 2mg pills
Xgovjw
ascorbic acid online buy - <a href="https://mdacidinfo.com/lopinavirritonavir/">lopinavir ritonavir cost</a> compro cost
Oehohv
order durex gel sale - <a href="https://xalaplinfo.com/latanoprosteyedrops/">cost xalatan</a> zovirax over the counter
Ubvypg
rogaine without prescription - <a href="https://hairlossmedinfo.com/finasteridehl/">purchase proscar generic</a> order finasteride
Joizeo
buy leflunomide without a prescription - <a href="https://infohealthybones.com/cartidin/">buy cartidin without prescription</a> brand cartidin
Oercps
buy verapamil tablets - <a href="https://infoheartdisea.com/valsartan/">buy valsartan generic</a> buy tenoretic pills
Rmwcma
atenolol canada - <a href="https://heartmedinfox.com/sotalol/">sotalol cost</a> coreg brand
Wvwywv
buy gasex pill - <a href="https://herbalinfomez.com/diabecon/">diabecon cost</a> diabecon online
Omppan
atorvastatin drug - <a href="https://infoxheartmed.com/nebivolol/">bystolic order</a> cheap nebivolol 20mg
Flkbla
buy cheap generic lasuna - <a href="https://infoherbalmz.com/diarex/">order diarex online cheap</a> buy himcolin online
Mgpxeu
buy generic norfloxacin online - <a href="https://gmenshth.com/">buy noroxin sale</a> confido tablets
Odawzv
buy finax generic - <a href="https://finmenura.com/alfuzosin/">uroxatral 10mg cost</a> uroxatral over the counter
Nijtwb
purchase speman without prescription - <a href="https://spmensht.com/finasteride/">finasteride tablets</a> cheap finasteride for sale
Wzfqnm
terazosin 5mg cost - <a href="https://hymenmax.com/">buy hytrin 5mg pill</a> buy dapoxetine 30mg online
Shkngb
order trileptal 300mg online - <a href="https://trileoxine.com/pirfenidone/">pirfenidone medication</a> synthroid online buy
Aiyylu
oral cyclosporine - <a href="https://asimusxate.com/gloperba/">cost gloperba</a> colchicine price
Xpxott
buy generic lactulose online - <a href="https://duphalinfo.com/">lactulose drug</a> order betahistine without prescription
Mqsuzf
order calcort generic - <a href="https://lazacort.com/brimonidine/">brimonidine online order</a> brimonidine where to buy
Fbiwqb
how to get besifloxacin without a prescription - <a href="https://besifxcist.com/carbocysteine/">order carbocysteine generic</a> order sildamax generic
Ltbhso
neurontin pill - <a href="https://aneutrin.com/">purchase neurontin online cheap</a> purchase azulfidine for sale
Jdkoxh
order benemid 500 mg pills - <a href="https://bendoltol.com/">probenecid where to buy</a> carbamazepine brand
Nqewhw
celecoxib pills - <a href="https://celespas.com/flavoxate/">buy urispas medication</a> buy indomethacin medication
Bjrigg
colospa 135mg cheap - <a href="https://coloxia.com/">buy colospa 135mg for sale</a> purchase cilostazol
Ktzngk
buy cambia without prescription - <a href="https://dicloltarin.com/aspirin/">order aspirin 75mg generic</a> buy generic aspirin online
Lbhvvc
rumalaya sale - <a href="https://rumaxtol.com/">oral rumalaya</a> buy endep 10mg without prescription
Uyktro
buy pyridostigmine for sale - <a href="https://mestonsx.com/">buy mestinon 60 mg pills</a> buy azathioprine online cheap
Ylekon
buy generic voveran - <a href="https://vovetosa.com/animodipine/">buy nimodipine online</a> nimodipine pills
Qcgjjn
lioresal canada - <a href="https://baclion.com/">baclofen for sale online</a> buy piroxicam 20 mg online cheap
Oixvuf
order mobic 7.5mg generic - <a href="https://meloxiptan.com/">generic meloxicam 7.5mg</a> ketorolac price
Qnnods
buy periactin generic - <a href="https://periheptadn.com/">periactin 4mg brand</a> order tizanidine pill
Esjkhg
cheap artane tablets - <a href="https://voltapll.com/diclofenacgel/">buy emulgel cheap</a> buy cheap diclofenac gel
Aveoem
cefdinir medication - <a href="https://omnixcin.com/aminocycline/"></a> order cleocin
Pwdbom
purchase accutane without prescription - <a href="https://aisotane.com/">brand isotretinoin 10mg</a> deltasone 5mg usa
Ruxwkd
order deltasone 40mg - <a href="https://apreplson.com/prednisolone/">buy omnacortil generic</a> purchase zovirax online
Gkhycy
acticin generic - <a href="https://actizacs.com/tretinoin/">tretinoin gel drug</a> tretinoin usa
Egsvbz
order betnovate sale - <a href="https://betnoson.com/awdifferin/">purchase differin for sale</a> buy monobenzone cream for sale
Bjjojb
where to buy metronidazole without a prescription - <a href="https://cenforcevs.com/">buy cenforce medication</a> cenforce 50mg usa
Zpkzqh
buy augmentin 625mg sale - <a href="https://alevonted.com/">levothroid oral</a> buy synthroid 100mcg online cheap
Munpoq
cleocin 300mg pills - <a href="https://indometnp.com/">indocin 50mg pills</a> indomethacin cheap
Vkjesj
buy losartan - <a href="https://cozartan.com/">buy cheap losartan</a> order generic keflex 250mg
Tvvkbi
cost eurax - <a href="https://aeuracream.com/caczone/">order aczone pills</a> buy aczone gel for sale
Gpcrba
order generic modafinil 200mg - <a href="https://sleepagil.com/phenergan/">phenergan ca</a> melatonin drug
Hdwpzr
buy xeloda 500 mg generic - <a href="https://xelocap.com/">capecitabine online order</a> danocrine 100mg canada
Geqoab
progesterone 200mg drug - <a href="https://apromid.com/clomipheneferto/">buy fertomid for sale</a> order clomiphene for sale
Xypuik
alendronate 70mg ca - <a href="https://pilaxmax.com/medroxyprogesterone/">buy provera 5mg pills</a> how to get medroxyprogesterone without a prescription
Qudncv
norethindrone buy online - <a href="https://norethgep.com/lumigan/">how to get lumigan without a prescription</a> yasmin without prescription
Ifgrgc
cabergoline 0.25mg uk - <a href="https://adostilin.com/alesse/">buy generic alesse over the counter</a> alesse medication
Zpzhdr
purchase yasmin sale - <a href="https://festrolp.com/letrozole/">order letrozole 2.5 mg without prescription</a> arimidex online buy
Sbwiqc
シルデナフィル - 50mg/100mg - <a href="https://jpedpharm.com/">バイアグラ 海外通販</a> シアリスの飲み方と効果
Khsrsp
プレドニン どこで買える - <a href="https://jpaonlinep.com/jazithromycin/">アジスロマイシン通販</a> ジスロマック は通販での購
Isbphy
プレドニン どこで買える - <a href="https://jpanfarap.com/jpadoxycycline/">ドキシサイクリン通販おすすめ</a> イソトレチノイン どこで買える
Junppt
eriacta lap - <a href="https://eriagra.com/fforzestf/">forzest delay</a> forzest week