APP开发,支付宝后台demo
签约就不说了,记得上传支付宝公钥密钥。
出现40247错误的,看下面解决方法:
1.没签约,所以没有权限
2.看下上传公钥密钥没有,用支付宝验签工具匹配一下公钥密钥
3.记得把请求参数给encoder编码
回调时候验签的时候给支付宝返回参数success,记得把网址复制到到浏览器看下success大小,java加了这个success会比通常的大一点,支付宝会不识别response.setHeader("Access-Control-Allow-Headers","X-Requested-With");
response.setHeader("Cache-Control","no-cache");
验签就不说了,挺简单的,就是步骤挺多。
publicstaticvoidmain(String[]args)throwsAlipayApiException,UnsupportedEncodingException{
Stringappid="";
StringnotifyUrl="";
StringprivateKey="";
StringpaymentOrder=UtilDate.getThree()+UtilDate.getOrderNum()+UtilDate.getThree();//订单编号
//支付金额
AlipayConfigalipayConfig=newAlipayConfig(appId,notifyUrl,privateKey);
//把请求参数打包成数组
Map<String,String>sParaTemp=newHashMap<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-ddhh:mm:ss",newDate()));
sParaTemp.put("version",alipayConfig.getVersion());
sParaTemp.put("notify_url",alipayConfig.getNotifyUrl());
sParaTemp.put("sign_type",alipayConfig.getSignType());
Map<String,String>bizContent=newHashMap<String,String>();
bizContent.put("total_amount","0.01");
bizContent.put("subject","");//支付宝订单信息
bizContent.put("out_trade_no",paymentOrder);
bizContent.put("product_code","QUICK_MSECURITY_PAY");
bizContent.put("goods_type","1");
bizContent.put("seller_id","");//不需要填默认为商户签约账号对应的支付宝用户ID
sParaTemp.put("biz_content",JSONUtil.map2json(bizContent));
StringsignString=AlipayCore.createLinkString(AlipayCore.paraFilter(sParaTemp));//待签名字符串
StringencodeSignString=AlipayCore.createLinkEncodeString(AlipayCore.paraFilter(sParaTemp));//格式key=value&key2=value2其中valueencode处理
System.out.println(signString);
//得到签名
Stringsign=AlipaySignature.rsa256Sign(signString,alipayConfig.getPrivateKey(),alipayConfig.getCharset());
StringsignEncode=URLEncoder.encode(sign,"UTF-8");
StringorderInfo=encodeSignString+"&sign="+signEncode;
System.out.println(orderInfo);
另,自己想带额外参数添加到extend_params这个里面,记得把他URLEncoder编码一下,里面的key和vuale值都是随便写别跟参数重名。