我正在尝试将Djnago的PayTm网关集成为后端,但是我的程序在生成checksumhash时遇到错误。 以下是我的代码段:
from django.db import models
class TrxnDetail(models.Model):
MID = models.CharField(max_length=20)
ORDER_ID = models.CharField(max_length=50)
CUST_ID = models.CharField(max_length=64)
TXN_AMOUNT = models.CharField(max_length=10)
CHANNEL_ID = models.CharField(max_length=3)
WEBSITE = models.CharField(max_length=30)
INDUSTRY_TYPE_ID = models.CharField(max_length=20)
MOBILE_NO = models.CharField(max_length=15)
EMAIL = models.CharField(max_length=50)
def __str__(self):
return self.ORDER_ID
from rest_framework import status
from rest_framework.decorators import api_view
from rest_framework.response import Response
from gateway.models import TrxnDetail
from gateway.serializers import TrxnSerializer
from gateway.Checksum import generate_checksum
from django.conf import settings
@api_view(['GET', 'POST'])
def snippet_list(request):
"""
List all code snippets, or create a new snippet.
"""
if request.method == 'GET':
snippets = TrxnDetail.objects.all()
serializer = TrxnSerializer(snippets, many=True)
return Response(serializer.data)
elif request.method == 'POST':
serializer = TrxnSerializer(data=request.data)
if serializer.is_valid():
serializer.save()
sdata=serializer.data
mid,order_id,cust_id,
txn_amount,channel_id,
website,industry_type_id,
mobile_no,email=sdata.get('MID'),sdata.get('ORDER_ID'),
sdata.get('CUST_ID'),sdata.get('TXN_AMOUNT'),
sdata.get('CHANNEL_ID'),sdata.get('WEBSITE'),
sdata.get('INDUSTRY_TYPE_ID'),sdata.get('MOBILE_NO'),
sdata.get('EMAIL'),
param_dict = dict()
param_dict['MID']=mid
param_dict['ORDER_ID']=order_id
param_dict['CUST_ID']=cust_id
param_dict['TXN_AMOUNT']=txn_amount
param_dict['CHANNEL_ID']=channel_id
param_dict['WEBSITE']=website
param_dict['INDUSTRY_TYPE_ID']=industry_type_id
param_dict['MOBILE_NO']=mobile_no
param_dict['EMAIL']=email
print(generate_checksum(param_dict,settings.PAYTM_MERCHANT_KEY))
return Response(serializer.data, status=status.HTTP_201_CREATED)
return Response(serializer.errors,status=status.HTTP_400_BAD_REQUEST)
我正在使用ModelSerializer和CheckSum.py
我遇到以下错误:Error Image
答案 0 :(得分:0)
如果您使用的是python 3,请确保先安装pycryptodome。 Checksum文件中的编码和解码功能的AES.new()函数需要utf-8编码参数。
用以下代码替换功能:
private function filterByRelationship($query, $keyword, $relativeTables)
{
foreach ($relativeTables as $relationship => $relativeColumns) {
$query->orWhereHas($relationship, function($relationQuery) use ($keyword, $relativeColumns) {
foreach ($relativeColumns as $key => $column) {
$clause = $key == 0 ? 'where' : 'orWhere';
$relationQuery->$clause($column, "LIKE", "%$keyword%");
}
});
}
return $query;
}
我希望能帮上忙。