Last active
August 29, 2015 14:14
-
-
Save eva0919/b3b27474243cc2b057f3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static boolean verify(WORequest r) { | |
// request all post argument | |
HashMap<String, String> myMap = new HashMap<String, String>(); | |
if(HypoUtility.safeTrim(r.stringFormValueForKey("MerchantID")).equals(MERCHANT_ID)){ | |
myMap.put("MerchantID", MERCHANT_ID); | |
} else{ | |
log.info("allpayAlipay MerchantID is not Our ID"); | |
return false; | |
} | |
myMap.put("MerchantTradeNo", HypoUtility.safeTrim(r.stringFormValueForKey("MerchantTradeNo")) ); | |
myMap.put("RtnCode", HypoUtility.safeTrim(r.stringFormValueForKey("RtnCode")) ); | |
myMap.put("TradeAmt", HypoUtility.safeTrim(r.stringFormValueForKey("RtnCode")) ); | |
myMap.put("RtnMsg", HypoUtility.safeTrim(r.stringFormValueForKey("RtnMsg")) ); | |
myMap.put("TradeNo", HypoUtility.safeTrim(r.stringFormValueForKey("TradeNo")) ); | |
myMap.put("PaymentDate", HypoUtility.safeTrim(r.stringFormValueForKey("PaymentDate")) ); | |
myMap.put("PaymentType", HypoUtility.safeTrim(r.stringFormValueForKey("PaymentType")) ); | |
myMap.put("PaymentTypeChargeFee", HypoUtility.safeTrim(r.stringFormValueForKey("PaymentTypeChargeFee")) ); | |
myMap.put("TradeDate", HypoUtility.safeTrim(r.stringFormValueForKey("TradeDate")) ); | |
myMap.put("SimulatePaid", HypoUtility.safeTrim(r.stringFormValueForKey("SimulatePaid")) ); | |
String hashKeyString = "HashKey=" + HashKey; | |
String hashIvString = "HashIV=" + HashIV; | |
String CheckMacValue = HypoUtility.safeTrim(r.stringFormValueForKey("CheckMacValue")); | |
String[] arguList = { "MerchantID", "MerchantTradeNo", | |
"RtnCode", "TradeAmt", "RtnMsg", "TradeNo", | |
"PaymentDate", "PaymentType", "PaymentTypeChargeFee", "TradeDate", | |
"SimulatePaid"}; | |
Arrays.sort(arguList); | |
if (!"1".equals(myMap.get("RtnCode") )) | |
{ | |
log.info("allpayAlipay RtnCode is not 1"); | |
return false; | |
} | |
StringBuffer tempS = new StringBuffer(); | |
tempS.append(hashKeyString + "&"); | |
for (int i = 0; i < arguList.length; i++) { | |
tempS.append(arguList[i] + "=" + myMap.get(arguList[i]) + "&"); | |
} | |
tempS.append(hashIvString); | |
String finalS =""; | |
MessageDigest md; | |
StringBuffer sb = new StringBuffer(); | |
try { | |
finalS = URLEncoder.encode(tempS.toString(), "UTF-8"); | |
finalS = finalS.toLowerCase(); | |
md = MessageDigest.getInstance("MD5"); | |
byte[] bytesOfMessage = finalS.getBytes("UTF-8"); | |
byte[] thedigest = md.digest(bytesOfMessage); | |
for (int i = 0; i < thedigest.length; ++i) { | |
sb.append(Integer.toHexString((thedigest[i] & 0xFF) | 0x100).substring( | |
1, 3)); | |
} | |
} catch (UnsupportedEncodingException | NoSuchAlgorithmException e) { | |
// TODO Auto-generated catch block | |
e.printStackTrace(); | |
} | |
if(myMap.get("SimulatePaid").equals("1")){ | |
log.info("Our CheckValue is : "); | |
log.info(sb.toString().toUpperCase()); | |
log.info("Allpay CheckValue is : "); | |
log.info(CheckMacValue); | |
} | |
if( sb.toString().toUpperCase().equals(CheckMacValue.toUpperCase()) ){ | |
return true; | |
}else{ | |
System.out.println(sb.toString()); | |
log.info("allpayAlipay CheckMacValue is not Correct!"); | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment