小程序支付java代码 小程序支付java代码是什么( 三 )


String payGateway = "";// 跳转到支付宝的url头
String securityCode="7nj9sczcnfc4n8366j46mrzsbqjksmzn";//securityCode(安全码);
String sign = makeUrl(hm,securityCode,"utf-8",payGateway);//securityCode(安全码);
hm.put("sign", sign);
hm.put("sign_type", "MD5");
PrintWriter out = response.getWriter();
out.println("form name='alipaysubmit' method='post'action='' ");
out.println("input type='hidden' name='service' value='" + hm.get("service") + "'");
out.println("input type='hidden' name='partner' value='" + hm.get("partner") + "'");
out.println("input type='hidden' name='seller_email' value='" + hm.get("seller_email") + "'");
out.println(““);
out.println("input type='hidden' name='subject' value='" + hm.get("subject") + "'");
out.println("input type='hidden' name='body' value='" + hm.get("body") + "'");
out.println("input type='hidden' name='total_fee' value='" + hm.get("total_fee") + "'");
out.println("input type='hidden' name='show_url' value='" + hm.get("show_url") + "'");
out.println("input type='hidden' name='return_url' value='" + hm.get("return_url") + "'");
out.println("input type='hidden' name='notify_url' value='" + hm.get("notify_url") + "'");
out.println("input type='hidden' name='payment_type' value='https://www.04ip.com/post/1'");
out.println("input type='hidden' name='sign' value='" + hm.get("sign") + "'");
out.println("input type='hidden' name='sign_type' value='" + hm.get("sign_type") + "'");
out.println("/form");
out.println("script");
out.println("document.alipaysubmit.submit()");
out.println("/script");
return null;
}
/**
* 根据传入的参数生成Alipay的支付URL
* @param hm 参数值
* @param securityCode 安全码
* @param charset 编码
* @param payGateway 支付宝gateway
@return
*/
public static String makeUrl(HashMap hm,String securityCode,String charSet,String payGateway) throws Exception{
List keys = new ArrayList(hm.keySet());
Collections.sort(keys);//支付宝要求参数必须按字母排序
StringBuffer content = new StringBuffer();
for (int i = 0; ikeys.size(); i++) {
content.append((String) keys.get(i));
content.append("=");
content.append((String) hm.get((String) keys.get(i)));
if (i != keys.size() - 1) {
content.append("");
}
}
content.append(securityCode);
String sign = DataUtil.MD5Encode(content.toString(), charSet);//MD5加密
return sign;
}
2、return_url的内容:
/**
* 支付宝支付完成以后,当前窗口会从支付宝的页面跳转回这个页面 。该页面称作“返回页”,
* 是同步被支付宝服务器所调用,可当作是支付完成后的提示信息页,如“您的某某某订单,多少金额已支付成功” 。
*/
public ActionForward AlipayReturn(ActionMapping mapping,
ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws Exception {
String alipayNotifyURL = "";
//String alipayNotifyURL = "?";//此路径是在上面链接地址无法起作用时替换使用 。
alipayNotifyURL = alipayNotifyURL+ "partner=2088002302055380notify_id="+ request.getParameter("notify_id");
// 获取支付宝ATN返回结果,true是正确的订单信息,false 是无效的
String responseTxt = check(alipayNotifyURL);
// 获得POST 过来参数设置到新的requestParams中
Map requestParams = request.getParameterMap();
List keys = new ArrayList(requestParams.keySet());
Collections.sort(keys);
StringBuffer content = new StringBuffer();
for (int i = 0; ikeys.size(); i++) {
String key=(String) keys.get(i);
if(!key.equals("")!key.equals("sign")!key.equals("sign_type")){
content.append((String) keys.get(i));
content.append("=");

推荐阅读