Android中的Freecharge钱包集成

时间:2017-02-22 09:33:51

标签: android

我正在使用Android中的Freecharge钱包集成。我们也购买了商家ID和集成密钥。

我按照Freecharge指南中的说明操作,但我在日志中遇到错误消息"校验和/校验和不匹配"

目前我正在等待免费客户服务部门回复错误

如果你们中的任何人整合了这个免费充值钱包,请帮助我解决这个问题。

我想出了代码截图和错误日志

代码

Code

代码继续...... Code Continue...

错误记录

Error Log

1 个答案:

答案 0 :(得分:0)

嗨,我遇到了同样的问题。

通过此代码生成校验和。

private void generateChecksum(String merchantKey) {


    JSONObject jsonObject = new JSONObject();


    checksumObj = new ChecksumObj(mEdtAmount.getText().toString(), "ANDROID", mEdtEmail.getText().toString(),
            "https://www.google.com", "merchantID", getTransactionID(), mEdtMobile.getText().toString(), "auth", "https://www.google.com");


    try {
        jsonObject.put("amount", checksumObj.getAmount());
        jsonObject.put("channel", checksumObj.getChannel());
        jsonObject.put("email", checksumObj.getEmail());
        jsonObject.put("furl", checksumObj.getFurl());
        jsonObject.put("merchantId", checksumObj.getMerchantId());
        jsonObject.put("merchantTxnId", checksumObj.getMerchantTxnId());
        jsonObject.put("mobile", checksumObj.getMobile());
        jsonObject.put("productInfo", checksumObj.getProductInfo());
        jsonObject.put("surl", checksumObj.getSurl());

    } catch (JSONException e) {
        e.printStackTrace();
    }

    String plainText = jsonObject.toString().concat(merchantKey).replace("\\/", "/");

    MessageDigest md = null;

    try {
        md = MessageDigest.getInstance("SHA-256");
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    }
    md.update(plainText.getBytes(Charset.defaultCharset()));
    byte[] mdbytes = md.digest();

    // convert the byte to hex format method 1

    StringBuffer checksum = new StringBuffer();
    for (int i = 0; i < mdbytes.length; i++) {
        checksum.append(Integer.toString((mdbytes[i] & 0xff) + 0x100, 16).substring(1));
    }

    jsonCheckSum = checksum.toString();

    requestMap();



}

CheckSumObj实现了Serializable。

public class ChecksumObj implements Serializable {
String amount, channel, customerName, email, furl, merchantId, merchantTxnId, mobile, productInfo, surl;

public ChecksumObj(String amount, String channel, String email, String furl, String merchantId, String merchantTxnId, String mobile, String productInfo, String surl) {
    this.amount = amount;
    this.channel = channel;
    this.email = email;
    this.furl = furl;
    this.merchantId = merchantId;
    this.merchantTxnId = merchantTxnId;
    this.mobile = mobile;
    this.productInfo = productInfo;
    this.surl = surl;
}


public String getAmount() {
    return amount;
}

public void setAmount(String amount) {
    this.amount = amount;
}

public String getChannel() {
    return channel;
}

public void setChannel(String channel) {
    this.channel = channel;
}

public String getCustomerName() {
    return customerName;
}

public void setCustomerName(String customerName) {
    this.customerName = customerName;
}

public String getEmail() {
    return email;
}

public void setEmail(String email) {
    this.email = email;
}

public String getFurl() {
    return furl;
}

public void setFurl(String furl) {
    this.furl = furl;
}

public String getMerchantId() {
    return merchantId;
}

public void setMerchantId(String merchantId) {
    this.merchantId = merchantId;
}

public String getMerchantTxnId() {
    return merchantTxnId;
}

public void setMerchantTxnId(String merchantTxnId) {
    this.merchantTxnId = merchantTxnId;
}

public String getMobile() {
    return mobile;
}

public void setMobile(String mobile) {
    this.mobile = mobile;
}

public String getProductInfo() {
    return productInfo;
}

public void setProductInfo(String productInfo) {
    this.productInfo = productInfo;
}

public String getSurl() {
    return surl;
}

public void setSurl(String surl) {
    this.surl = surl;
}}

请求的HashMap。

    private void requestMap() {
    checkoutRequestMap = new HashMap<>();
    checkoutRequestMap.put("amount", checksumObj.getAmount());
    checkoutRequestMap.put("channel", "ANDROID");
    checkoutRequestMap.put("email", checksumObj.getEmail());
    checkoutRequestMap.put("furl", "https://www.google.com");
    checkoutRequestMap.put("merchantId", "MerchantID");
    checkoutRequestMap.put("merchantTxnId", checksumObj.getMerchantTxnId());
    checkoutRequestMap.put("mobile", checksumObj.getMobile());
    checkoutRequestMap.put("productInfo", "auth");
    checkoutRequestMap.put("surl", "https://www.google.com");
    checkoutRequestMap.put("checksum", jsonCheckSum);

    FreeChargePaymentSdk.startSafePayment(FreeChargeMainActivity.this, checkoutRequestMap, freeChargePaymentCallback);

}

TransactionID随机。

 private String getTransactionID() {

    SecureRandom random = new SecureRandom();

    return new BigInteger(48, random).toString(16) + mEdtMobile.getText().toString().substring(0, 5);

}

FreeCharge回调。

  FreeChargePaymentCallback freeChargePaymentCallback = new FreeChargePaymentCallback() {

    @Override
    public void onTransactionFailed(HashMap<String, String> txnFailResponse) {
        Toast.makeText(FreeChargeMainActivity.this, txnFailResponse.get("errorMessage"), Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onTransactionCancelled() {
        Toast.makeText(FreeChargeMainActivity.this, "user cancelled the transaction", Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onTransactionSucceeded(HashMap<String, String> txnSuccessResponse) {
        Toast.makeText(FreeChargeMainActivity.this, txnSuccessResponse.get("status"), Toast.LENGTH_SHORT).show();
        mEdtMobile.setText("");
        mEdtAmount.setText("");
        mEdtEmail.setText("");
        clearFreeChargeCache();
    }

    @Override
    public void onErrorOccurred(FreechargeSdkException sdkError) {
        Toast.makeText(FreeChargeMainActivity.this, sdkError.getErrorMessage(), Toast.LENGTH_SHORT).show();
    }
};

的build.gradle(项目级)

allprojects {
repositories {
    jcenter()
    maven {
        url "https://s3-ap-southeast-1.amazonaws.com/godel-release/godel/"
    }
}}

的build.gradle(应用级)

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
    exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'in.freecharge.checkout.android:freecharge-checkout-android-sdk:2.2@aar'
compile 'in.juspay:godel:0.6.12.1423'
testCompile 'junit:junit:4.12'}

希望这有帮助。快乐的编码。