React Native Jazzcash支付集成V2.0

xkrw2x1b  于 2023-06-24  发布在  React
关注(0)|答案(3)|浏览(146)

我正在开发基于REST的API版本2.0。它不断地给我错误
请为pp_SecureHash提供有效值
它在“页面重定向”的情况下工作正常,因此哈希键生成方法是正确的,问题是参数(可能是一些丢失/额外/错误的数据)。我做错了什么

{ “uri”: “https://sandbox.jazzcash.com.pk/ApplicationAPI/API/2.0/Purchase/DoMWalletTransaction”, “method”: “POST”, “body”: “pp_Amount=1100&pp_BillReference=billRef&pp_CNIC=345678&pp_Description=jazzcash&pp_Language=EN&pp_MerchantID=xyz&pp_MobileNumber=03123456789&pp_Password=xyz&pp_ReturnURL=https://sandbox.jazzcash.com.pk/ApplicationAPI/API/2.0/Purchase/DoMWalletTransaction&pp_SecureHash=BC3BABD0481A2FA756F2E16CE15FC6F8029D40E23B974065668CCEAC300B80AE&pp_TxnCurrency=PKR&pp_TxnDateTime=20220406132730&pp_TxnExpiryDateTime=20220406142730&pp_TxnRefNo=T20220406142730&ppmpf_1=1&ppmpf_2=2&ppmpf_3=3&ppmpf_4=4&ppmpf_5=5” }
unftdfkk

unftdfkk1#

您的pp_SecureHash值需要进行HmacSHA256编码。

var sHash = HMACSHA256Encode(hash, jazz.salt);

您可以参考此代码示例来实现您的要求。

**C#:**生成pp_SecureHash()

1szpjjfi

1szpjjfi2#

请检查您的商户ID、密码和盐密钥。如果您的任何信息是错误的,也是通过错误。仔细阅读文档。如果添加版本1.2,文档中提到了1.1,它将无法工作,并通过相同的错误。提供有效安全
如果你确定其他信息是正确的,那么你可以使用下面的方法来生成安全的ssh

$post_data =  array(
            "pp_Version"            => Config::get('constants.jazzcash.VERSION'),
            "pp_TxnType"            => "MWALLET",
            "pp_Language"           => Config::get('constants.jazzcash.LANGUAGE'),
            "pp_MerchantID"         => Config::get('constants.jazzcash.MERCHANT_ID'),
            "pp_SubMerchantID"      => "",
            "pp_Password"           => Config::get('constants.jazzcash.PASSWORD'),
            "pp_BankID"             => "TBANK",
            "pp_ProductID"          => "RETL",
            "pp_TxnRefNo"           => $pp_TxnRefNo,
            "pp_Amount"             => $pp_Amount,
            "pp_TxnCurrency"        => Config::get('constants.jazzcash.CURRENCY_CODE'),
            "pp_TxnDateTime"        => $pp_TxnDateTime,
            "pp_BillReference"      => "billRef",
            "pp_Description"        => "Description of transaction",
            "pp_TxnExpiryDateTime"  => $pp_TxnExpiryDateTime,
            "pp_ReturnURL"          => Config::get('constants.jazzcash.RETURN_URL'),
            "pp_SecureHash"         => "",
            "ppmpf_1"               => "1",
            "ppmpf_2"               => "2",
            "ppmpf_3"               => "3",
            "ppmpf_4"               => "4",
            "ppmpf_5"               => "5",
        );
private function get_SecureHash($data_array)
    {
        ksort($data_array);
        
        $str = '';
        foreach($data_array as $key => $value){
            if(!empty($value)){
                $str = $str . '&' . $value;
            }
        }
        
        $str = Config::get('constants.jazzcash.INTEGERITY_SALT').$str;
        
        $pp_SecureHash = hash_hmac('sha256', $str, Config::get('constants.jazzcash.INTEGERITY_SALT'));
        
        //echo '<pre>';
        //print_r($data_array);
        //echo '</pre>';
        
        return $pp_SecureHash;
    }

最后通过调用这个方法你可以得到安全密钥

$pp_SecureHash = $this->get_SecureHash($post_data);
qacovj5a

qacovj5a3#

C#开发者代码

为键值创建简单类模型

public class KeyValueModel
{
    public string Key { get; set; }
    public string Value { get; set; }
}

为Json对象创建Jazz Cash模型以用于发布请求

var model = new JazzCashModel
{
    pp_Version = "1.1",
    pp_TxnType = "MWALLET",
    pp_Language = "EN",
    pp_MerchantID = "MC58085",
    pp_SubMerchantID = "",
    pp_Password = "33t8ve7s5z",
    pp_BankID = "",
    pp_ProductID = "",
    pp_TxnRefNo = "T20230623141244",
    pp_Amount = "50000",
    pp_TxnCurrency = "PKR",
    pp_TxnDateTime = "20230623141244",
    pp_BillReference = "billref",
    pp_Description = "Description of transaction",
    pp_TxnExpiryDateTime = "20230623141244",
    pp_ReturnURL = "www.fqmsys.com",
    pp_SecureHash = "",
    ppmpf_1 = "03426791550",
    ppmpf_2 = "",
    ppmpf_3 = "",
    ppmpf_4 = "",
    ppmpf_5 = ""
};

创建键值模型的列表

var list = new List<KeyValueModel>();

list.Add(new KeyValueModel { Key = "pp_Version", Value =model.pp_Version});
list.Add(new KeyValueModel { Key = "pp_TxnType", Value =model.pp_TxnType});
list.Add(new KeyValueModel { Key = "pp_Language", Value =model.pp_Language});
list.Add(new KeyValueModel { Key = "pp_MerchantID", Value =model.pp_MerchantID});
list.Add(new KeyValueModel { Key = "pp_SubMerchantID", Value =model.pp_SubMerchantID});
list.Add(new KeyValueModel { Key = "pp_Password", Value =model.pp_Password});
list.Add(new KeyValueModel { Key = "pp_BankID", Value =model.pp_BankID});
list.Add(new KeyValueModel { Key = "pp_ProductID", Value =model.pp_ProductID});
list.Add(new KeyValueModel { Key = "pp_TxnRefNo", Value =model.pp_TxnRefNo});
list.Add(new KeyValueModel { Key = "pp_Amount", Value =model.pp_Amount});
list.Add(new KeyValueModel { Key = "pp_TxnCurrency", Value =model.pp_TxnCurrency});
list.Add(new KeyValueModel { Key = "pp_TxnDateTime", Value =model.pp_TxnDateTime});
list.Add(new KeyValueModel { Key = "pp_BillReference", Value =model.pp_BillReference});
list.Add(new KeyValueModel { Key = "pp_Description", Value =model.pp_Description});
list.Add(new KeyValueModel { Key = "pp_TxnExpiryDateTime", Value =model.pp_TxnExpiryDateTime});
list.Add(new KeyValueModel { Key = "pp_ReturnURL", Value =model.pp_ReturnURL});
list.Add(new KeyValueModel { Key = "ppmpf_1", Value =model.ppmpf_1});
list.Add(new KeyValueModel { Key = "ppmpf_2", Value =model.ppmpf_2});
list.Add(new KeyValueModel { Key = "ppmpf_3", Value =model.ppmpf_3});
list.Add(new KeyValueModel { Key = "ppmpf_4", Value =model.ppmpf_4});
list.Add(new KeyValueModel { Key = "ppmpf_5", Value =model.ppmpf_5});

使用键对列表进行排序

list = list.OrderBy(x => x.Key).ToList();
var hash = "";
foreach (var item in list)
{
    if (string.IsNullOrEmpty(item.Value))
    {
        continue;
    }
    if (list.IndexOf(item)!=0 && (list.IndexOf(item) < list.Count - 1))
    {
        if (!string.IsNullOrEmpty(item.Value))
        {
            hash += "&";
        }
    }
    hash += item.Value;
   
}

使作为哈希字符串和计算哈希与盐你的盐密钥和哈希

var secure_has = ComputeHashWithSalt(hash,saltKey);

一种哈希计算方法

string ComputeHashWithSalt(string input, string salt)
{
string combinedString =   salt+"&"+input;
byte[] saltKeyBytes = Encoding.UTF8.GetBytes(salt);
byte[] inputBytes = Encoding.UTF8.GetBytes(combinedString);
using (HMACSHA256 sha256 = new HMACSHA256(saltKeyBytes))
{
   
    byte[] hashBytes = sha256.ComputeHash(inputBytes);
    string hashedString = BitConverter.ToString(hashBytes).Replace("-", "");
    return hashedString;
}

}

相关问题