我有一本字典,我用排序值創建字符串,並在字典字段值的開頭添加每個字段值的長度。 我要更新並排這個值方面,我必須散列它:如何並排更新字典值?
但這字符串格式就是這樣。
25http://a1ff569e.ngrok.io/
2TR
[email protected]
3Adı
6Soyadı
1105316806562
3000
164355084355084358
212
42018
8OPU_TEST
192017-08-28 10:24:57
8Ürünkodu
15Ürün Açıklaması
9Ürün İsmi
3100
11
7Test123
15
218
8CCVISAMC
3TRY
如何更新該字符串值並排像下面?
**我知道我可以打印與最終hashstring =「」但像,這是不更新hashstring varabile的價值只是表示這樣的,**
25http://a1ff569e.ngrok.io/ 2TR [email protected] 3Adı 6Soyadı 8PYKDMNSZ 192017-08-28 10時24分57秒 8Ürünkodu 15ÜrünAçıklaması 9ÜrünISMI 7Test123 8CCVISAMC 3TRY
# Importing required libraries for sample.
from datetime import datetime
import hmac
import hashlib
from urllib.parse import urlencode
from urllib.request import Request, urlopen
# Endpoint
url = "https://secure.payu.com.tr/order/alu/v3"
# PayU Merchant's Secret Key
secret = 'SECRET_KEY'
# Array Begin
array = {
# PayU Merchant's Merchant ID
'MERCHANT': "OPU_TEST",
'ORDER_REF': "Test123",
'ORDER_DATE': datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S'),
'BACK_REF': "http://a1ff569e.ngrok.io/",
'ORDER_PNAME[0]': "Ürün İsmi",
'ORDER_PCODE[0]': "Ürünkodu",
'ORDER_PINFO[0]': "Ürün Açıklaması",
'ORDER_PRICE[0]': "100",
'ORDER_VAT[0]': "18",
'ORDER_QTY[0]': "1",
'ORDER_SHIPPING': "5",
'PRICES_CURRENCY': "TRY",
'PAY_METHOD': "CCVISAMC",
'SELECTED_INSTALLMENTS_NUMBER': "2",
'CC_NUMBER': "4355084355084358",
'EXP_MONTH': "12",
'EXP_YEAR': "2018",
'CC_CVV': "000",
'BILL_FNAME': "Adı",
'BILL_LNAME': "Soyadı",
'BILL_PHONE': "05316806562",
'BILL_EMAIL': "[email protected]",
'BILL_COUNTRYCODE': "TR",
}
# Sorting Array params
for k, v in sorted(array.items()):
# Adding the length of each field value at the beginning of field value
hashstring = str(len(v)) + str(v)
print(hashstring)
# Calculating ORDER_HASH
signature = hmac.new(secret.encode('utf-8'), hashstring.encode('utf-8'), hashlib.md5).hexdigest()
# Adding ORDER_HASH param to dictionary
array['ORDER_HASH'] = signature
print(signature)
print()
# Sending Request to Endpoint
request = Request(url, urlencode(array).encode())
json = urlopen(request).read().decode()
# Printing result
print(json)
你能澄清一點嗎?試圖理解你的意思有些困難。您未能達到的理想輸出是什麼? – EsotericVoid
你可以試試'print(hashstring +「」,end =「」)'?這將得到您想要的輸出。 –
@ N.Ivanov Ivanov是的,我可以得到輸出結束=「」但這不是更新hashstring的值。我使用下面的代碼從字典中獲取值並進行排序,然後得到長度,然後我必須對該字符串進行散列處理,但在我的問題中創建了散列字符串。 #排序數組參數 for k,v in sort(array.items()): #在字段值的開頭添加每個字段值的長度 hashstring = str(len(v))+ str(v ) print(hashstring +「」,end =「」) #計算ORDER_HASH signature = hmac.new(secret.encode('utf-8'),hashstring.encode('utf-8'),hashlib.md5) .hexdigest() –