我正在尝试将 Easypaisa 付款集成到我的应用程序中。我有一个商家帐户。
这是我的代码
const requestBody = 'storeId=xxxx&amount=xx&postBackURL=xxx&orderRefNum=xx';
const requestHeader = {
'Accept': 'application/json',
'Content-Type': 'application/x-www-form-urlencoded',
};
这里是react-native-webview
<WebView
source={{
uri: 'https://easypay.easypaisa.com.pk/easypay/Index.jsf',
headers: requestHeader,
body: requestBody,
method: 'POST',
}}
/>
这是我面临的错误
我尝试了很多解决方案,但没有取得任何成功,也没有找到与 Easypaisa 相关的任何解决方案或正确的文档。
我为此使用了 3 个软件包。
import AesJs from 'aes-js';
import { Buffer } from 'buffer';
import queryString, { stringify } from 'query-string';
并解决了这个问题
// 使用easypaisa HashKey以AES、ECB模式生成字节加密
步骤1
const aes = new AesJs.ModeOfOperation.ecb(AesJs.utils.utf8.toBytes(HASH_KEY));
您可以从商家帐户生成哈希密钥。
第2步
pkcs5Pad
function pkcs5Pad(text: string, blockSize: number): string {
const pad = blockSize - (text.length % blockSize);
return text + String.fromCharCode(pad).repeat(pad);
}
将对象转换为字符串
function convertObjectToString(obj: any): string {
let data = '';
Object.keys(obj)
.sort()
.forEach((key) => {
data += `${key}=${obj[key]}` + '&';
});
return data.slice(0, data.length - 1);
}
第3步
// 生成HashMapReq
const hasMapReq = Buffer.from(aes.encrypt(Buffer.from(
pkcs5Pad(convertObjectToString(requestBody), 16))))
.toString(
'base64',
);
将您的 hashReq 附加到请求正文中并享受。
可以分享一下代码吗?喀什艾哈迈德