Not to mention the contract, remember to upload the Alipay public key. If there is a 40247
error, see the following solutions:
1. No contract, so no authority When verifying the signature, return the parameter success to Alipay. Remember to copy the URL to the browser to see the size of the success. If you add this success to java, it will be a bit larger than the usual one. Alipay will not recognize the response.setHeader("Access-Control-Allow -Headers", "X-Requested-With"); response.setHeader("Cache-Control", "no-cache"); Not to mention the signature verification, it is very simple, but there are many steps. public static void main(String[] args) throws AlipayApiException, UnsupportedEncodingException { String appId = ""; String notifyUrl = ""; String privateKey = ""; String paymentOrder =UtilDate.getThree()+ UtilDate.getOrderNum() + UtilDate. getThree(); //Order ID //Payment amount
AlipayConfig alipayConfig = new AlipayConfig(appId, notifyUrl, privateKey);
//把请求参数打包成数组
Map<String, String> sParaTemp = new HashMap<String, String>();
sParaTemp.put("app_id", alipayConfig.getAppId());
sParaTemp.put("method", alipayConfig.getMethod());
sParaTemp.put("format", alipayConfig.getFormat());
sParaTemp.put("charset", alipayConfig.getCharset());
sParaTemp.put("timestamp", DatetimeUtil.convertDateToString("yyyy-MM-dd hh:mm:ss", new Date()));
sParaTemp.put("version", alipayConfig.getVersion());
sParaTemp.put("notify_url", alipayConfig.getNotifyUrl());
sParaTemp.put("sign_type",alipayConfig.getSignType());
Map<String, String> bizContent = new HashMap<String, String>();
bizContent.put("total_amount", "0.01");
bizContent.put("subject", ""); //Alipay order information
bizContent. put("out_trade_no", paymentOrder);
bizContent.put("product_code", "QUICK_MSECURITY_PAY");
bizContent.put("goods_type", "1");
bizContent.put("seller_id", ""); //no Need to fill in the Alipay user ID corresponding to the merchant's contract account by default
sParaTemp.put("biz_content", JSONUtil.map2json(bizContent));
String signString = AlipayCore.createLinkString(AlipayCore.paraFilter(sParaTemp)); //String to be signed
String encodeSignString = AlipayCore. createLinkEncodeString(AlipayCore.paraFilter(sParaTemp)); //Format key=value&key2=value2 where value encode is processed
System.out.println(signString);
//Get the signature
String sign = AlipaySignature.rsa256Sign(signString, alipayConfig.getPrivateKey(), alipayConfig.getCharset());
String signEncode = URLEncoder.encode(sign, "UTF-8") ;
String orderInfo = encodeSignString + "&sign=" + signEncode;
System.out.println(orderInfo); In
addition, if you want to add extra parameters to extend_params, remember to encode his URLEncoder, the key and vuale values are both Just write it without the same name as the parameter.
APP development, Alipay background demo
Guess you like
Origin http://43.154.161.224:23101/article/api/json?id=326056806&siteId=291194637
Ranking