目录
微信app支付
appid-18位,appsecret -32位
商户号 mchId,mchKey
keyPath: /root/cert/apiclient_cert.p12
payUrl: https://api.mch.weixin.qq.com/pay/unifiedorder
refundPath: https://api.mch.weixin.qq.com/secapi/pay/refund
notifyUrl: https:xxxxxxxx
支付宝app支付
url-支付宝网关:
appId
应用公钥证书appCertPath
支付宝公钥证书alipayCertPath
支付宝根证书alipayRootCertPath
notifyUrl-服务器异步通知页面路径
微信支付开发文档:https://pay.weixin.qq.com/wiki/doc/api/index.html
微信app支付
appid-18位,appsecret -32位
商户号 mchId,mchKey
账户中心/API安全/设置密钥 查看
注意这个需要你在电脑上安装操作证书,才能看到
设置的时候会有一个验证
keyPath: /root/cert/apiclient_cert.p12
为服务器API安全证书apiclient_cert.p12,的存放路径
商户后台自己点击下载即可,http://kf.qq.com/faq/161222NneAJf161222U7fARv.html
开发所需的接口API证书、密钥,请登录微信支付商户平台,点击【账户中心】->【账户设置】->【API安全】->【下载证书】中,下载及设置;如未申请证书,可按照上面提示一步步申请(下载-解压-申请-复制)
payUrl: https://api.mch.weixin.qq.com/pay/unifiedorder
统一下单:商户系统先调用该接口在微信支付服务后台生成预支付交易单,返回正确的预支付交易会话标识后再在APP里面调起支付。
refundPath: https://api.mch.weixin.qq.com/secapi/pay/refund
申请退款:当交易发生之后一段时间内,由于买家或者卖家的原因需要退款时,卖家可以通过退款接口将支付款退还给买家,微信支付将在收到退款请求并且验证成功之后,按照退款规则将支付款按原路退到买家帐号上。
notifyUrl: https:xxxxxxxx
notifyUrl: 该链接是通过【统一下单API】中提交的参数notifyUrl设置,如果链接无法访问,商户将无法接收到微信通知,用于接收微信返回的接口
支付宝app支付
url-支付宝网关:
url: https://openapi.alipay.com/gateway.do
appId
登陆https://openhome.alipay.com支付宝开放平台查看
应用私钥appPrivateKey
https://docs.open.alipay.com/291/105971/,设置接口加签方式过程中生成的私钥
应用公钥证书appCertPath
支付宝公钥证书alipayCertPath
支付宝根证书alipayRootCertPath
支付宝文档参考链接:https://opendocs.alipay.com/open/291/105971/
按照文档一步步就可以生成公钥证书及私钥等相关文件
notifyUrl-服务器异步通知页面路径
支付回调路径,需http://或者https://格式的完整路径,不能加?id=123这类自定义参数,必须外网可以正常访问,与微信此参数意思相同
OK,基本一个完整的支付业务需要的相关参数都在这里,后续有需要再补充。
java支付宝提现功能,单笔转账到支付宝账户(公钥证书方式)
/*** 单笔转账到支付宝账号* @author zhouhehe* @param tradingNo 商户转账唯一订单号。发起转账来源方定义的转账单据ID,用于将转账回执通知给来源方。不同来源方给出的ID可以重复,同一个来源方必须保证其ID的唯一性。只支持半角英文、数字,及“-”、“_”。 * @param amount 转账金额,单位:元。只支持2位小数,小数点前最大支持13位,金额必须大于等于0.1元。* @param payeeAccount 收款方账户。与payee_type配合使用。付款方和收款方不能是同一个账户。 * @param remark 转账备注(支持200个英文/100个汉字)。当付款方为企业账户,且转账金额达到(大于等于)50000元,remark不能为空。收款方可见,会展示在收款用户的收支详情中。* @return* @throws AlipayApiException*/public ResponseDataVo<Map<String, Object>> alipayTransfer(String tradingNo,String amount,String payeeAccount,String remark) throws AlipayApiException {//构造clientCertAlipayRequest certAlipayRequest = new CertAlipayRequest();certAlipayRequest.setServerUrl(ALIPAY_URL);certAlipayRequest.setAppId(APP_ID);certAlipayRequest.setPrivateKey(APP_PRIVATE_KEY);certAlipayRequest.setFormat("json");certAlipayRequest.setCharset(CHARSET);certAlipayRequest.setSignType("RSA2");//设置应用公钥证书路径certAlipayRequest.setCertPath(APP_CERT_PAHT);//设置支付宝公钥证书路径certAlipayRequest.setAlipayPublicCertPath(ALIPAY_CERT_PATH);//设置支付宝根证书路径certAlipayRequest.setRootCertPath(ALIPAY_ROOT_CERT_PATH);AlipayClient alipayClient = new DefaultAlipayClient(certAlipayRequest);AlipayFundTransToaccountTransferRequest request = new AlipayFundTransToaccountTransferRequest();Alipay alipay = new Alipay();alipay.setOut_biz_no(tradingNo);alipay.setPayee_type(PAYEE_TYPE);alipay.setAmount(amount);alipay.setPayer_show_name("******服务有限公司");alipay.setPayee_account(payeeAccount);//alipay.setPayee_real_name("哈哈哈哈");alipay.setRemark(remark);// 转成json格式放入String json = new Gson().toJson(alipay);request.setBizContent(json);AlipayFundTransToaccountTransferResponse response = null;Map<String, Object> map = new HashMap<String, Object>();try {response = alipayClient.certificateExecute(request);if ("10000".equals(response.getCode())) {map.put("code", response.getCode());map.put("msg", response.getMsg());map.put("subCode", response.getSubCode());map.put("subMsg", response.getSubMsg());map.put("tradingNo", response.getOutBizNo());map.put("orderId", response.getOrderId());map.put("payDate", response.getPayDate());map.put("des", "转账成功");return ResponseDataVo.success(map);} else {map.put("code", response.getCode());map.put("msg", response.getMsg());map.put("subCode", response.getSubCode());map.put("subMsg", response.getSubMsg());map.put("tradingNo", response.getOutBizNo());map.put("orderId", response.getOrderId());map.put("payDate", response.getPayDate());map.put("des", "转账失败");return new ResponseDataVo<Map<String,Object>>(map, ResponseConstant.ERROR_CODE, "转账失败");}} catch (AlipayApiException e) {e.printStackTrace();map.put("success", "false");map.put("des", "转账失败!");return new ResponseDataVo<Map<String,Object>>(map, ResponseConstant.ERROR_CODE, "转账失败");}}/*** 查询转账订单接口* @author zhouhehe* @param tradingNo 交易号 商户转账唯一订单号,分润系统唯一* @return* @throws AlipayApiException*/public ResponseDataVo<Map<String, Object>> alipayFundTransOrderQuery(String tradingNo) throws AlipayApiException {// 构造clientCertAlipayRequest certAlipayRequest = new CertAlipayRequest();certAlipayRequest.setServerUrl(ALIPAY_URL);certAlipayRequest.setAppId(APP_ID);certAlipayRequest.setPrivateKey(APP_PRIVATE_KEY);certAlipayRequest.setFormat("json");certAlipayRequest.setCharset(CHARSET);certAlipayRequest.setSignType("RSA2");// 设置应用公钥证书路径certAlipayRequest.setCertPath(APP_CERT_PAHT);// 设置支付宝公钥证书路径certAlipayRequest.setAlipayPublicCertPath(ALIPAY_CERT_PATH);// 设置支付宝根证书路径certAlipayRequest.setRootCertPath(ALIPAY_ROOT_CERT_PATH);AlipayClient alipayClient = new DefaultAlipayClient(certAlipayRequest);AlipayFundTransOrderQueryRequest request = new AlipayFundTransOrderQueryRequest();Alipay alipay = new Alipay();alipay.setOut_biz_no(tradingNo);// 转成json格式放入String json = new Gson().toJson(alipay);request.setBizContent(json);AlipayFundTransOrderQueryResponse response = null;Map<String, Object> map = new HashMap<String, Object>();try {response = alipayClient.certificateExecute(request);if ("10000".equals(response.getCode())) {map.put("code", response.getCode());map.put("msg", response.getMsg());map.put("orderId", response.getOrderId());map.put("payDate", response.getPayDate());map.put("status", response.getStatus());map.put("subCode", response.getSubCode());// 详情状态码map.put("des", "转账成功");return ResponseDataVo.success(map);} else {map.put("code", response.getCode());map.put("msg", response.getMsg());map.put("orderId", response.getOrderId());map.put("payDate", response.getPayDate());map.put("status", response.getStatus());map.put("subCode", response.getSubCode());// 详情状态码map.put("failReason", response.getFailReason());map.put("des", "转账失败");return new ResponseDataVo<Map<String,Object>>(map, ResponseConstant.ERROR_CODE, "转账失败");}} catch (AlipayApiException e) {e.printStackTrace();map.put("success", "false");map.put("des", "转账失败!");return new ResponseDataVo<Map<String,Object>>(map, ResponseConstant.ERROR_CODE, "转账失败");}}
支付宝支付公钥证书方式
//构造client
CertAlipayRequest certAlipayRequest = new CertAlipayRequest();
//设置网关地址
certAlipayRequest.setServerUrl("https://openapi.alipay.com/gateway.do");
//设置应用Id
certAlipayRequest.setAppId(app_id);
//设置应用私钥
certAlipayRequest.setPrivateKey(privateKey);
//设置请求格式,固定值json
certAlipayRequest.setFormat("json");
//设置字符集
certAlipayRequest.setCharset(charset);
//设置签名类型
certAlipayRequest.setSignType(sign_type);
//设置应用公钥证书路径
certAlipayRequest.setCertPath(app_cert_path);
//设置支付宝公钥证书路径
certAlipayRequest.setAlipayPublicCertPath(alipay_cert_path);
//设置支付宝根证书路径
certAlipayRequest.setRootCertPath(alipay_root_cert_path);
//构造client
AlipayClient alipayClient = new DefaultAlipayClient(certAlipayRequest);//实例化具体API对应的request类,类名称和接口名称对应,当前调用接口名称:alipay.trade.app.pay
AlipayTradeAppPayRequest request = new AlipayTradeAppPayRequest();
//SDK已经封装掉了公共参数,这里只需要传入业务参数。以下方法为sdk的model入参方式(model和biz_content同时存在的情况下取biz_content)。
AlipayTradeAppPayModel model = new AlipayTradeAppPayModel();
model.setBody("我是测试数据");
model.setSubject("App支付测试Java");
model.setOutTradeNo(outtradeno);
model.setTimeoutExpress("30m");
model.setTotalAmount("0.01");
model.setProductCode("QUICK_MSECURITY_PAY");
request.setBizModel(model);
request.setNotifyUrl("商户外网可以访问的异步地址");
try {//这里和普通的接口调用不同,使用的是sdkExecuteAlipayTradeAppPayResponse response = alipayClient.sdkExecute(request);System.out.println(response.getBody());//就是orderString 可以直接给客户端请求,无需再做处理。} catch (AlipayApiException e) {e.printStackTrace();
}//异步回调
//获取支付宝POST过来反馈信息
Map<String,String> params = new HashMap<String,String>();
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);
}
//切记alipaypublickey是支付宝的公钥,请去open.alipay.com对应应用下查看。
//boolean AlipaySignature.rsaCertCheckV1(Map<String, String> params, String publicKeyCertPath, String charset,String signType)
boolean flag = AlipaySignature.rsaCertCheckV1(params, publicKeyCertPath, charset,"RSA2")