支付宝返回页验证失败——mysign.equals(request.getParameter("sign"))


import com.iim.timeeb.common.AlipayConfig;
import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;

public class AlipayCheck {

    public static Map check(HttpServletRequest request) throws UnsupportedEncodingException {
        String get_order = "";
        String get_total_fee = "";
        String get_subject = "";
        String get_body = "";
        String extra_common_param = "";
        String alipayNotifyURL = "http://notify.alipay.com/trade/notify_query.do?"
                + "partner="
                + AlipayConfig.partnerID
                + "&notify_id="
                + request.getParameter("notify_id");
        String responseTxt = CheckURL.check(alipayNotifyURL);
        Map params = new HashMap();
        Map requestParams = request.getParameterMap();
        for (Iterator iter = requestParams.keySet().iterator(); iter.hasNext();) {
            String name = (String) iter.next();
            String[] values = (String[]) requestParams.get(name);
            String valueStr = "";
            for (int i = 0; i < values.length; i++) {
                valueStr = (i == values.length - 1) 
				? valueStr + values[i] : valueStr + values[i] + ",";
            }
            valueStr = new String(valueStr.getBytes("ISO-8859-1"), "utf-8");
            params.put(name, valueStr);
        }
        String mysign = SignatureHelper_return.sign(params, AlipayConfig.key);
        boolean flag = false;
        if (mysign.equals(request.getParameter("sign")) && responseTxt.equals("true")) {
            if (request.getParameter("trade_status").equals("TRADE_FINISHED") 
		|| request.getParameter("trade_status").equals("TRADE_SUCCESS")) {
                get_order = request.getParameter("out_trade_no");
                get_total_fee = request.getParameter("total_fee");
                get_subject = request.getParameter("subject");
                get_body = request.getParameter("body");
                extra_common_param = request.getParameter("extra_common_param");
                flag = true;
            }
        }
        //返回需要的参数
        Map returnMap = new HashMap();
        returnMap.put("flag", flag);
        returnMap.put("get_order", get_order);
        returnMap.put("get_total_fee", get_total_fee);
        returnMap.put("get_subject", get_subject);
        returnMap.put("get_body", get_body);
        returnMap.put("extra_common_param", extra_common_param);
        return returnMap;
    }
}
 
支付宝在返回页面的验证中,有时候会遇到验证失败的问题,即这个验证不对:

mysign.equals(request.getParameter("sign")) 

出现这问题如果实在调试不好了,可以试试加上上面黄色的代码,也就是编码问题:

valueStr = new String(valueStr.getBytes("ISO-8859-1"), "utf-8");

这个问题以前遇到过一次解决了,这次忘了,害得我又调试了好长时间,在此笔记一下!

 

你可能感兴趣的:(支付宝接口,返回页验证失败,"utf-8");)