微信/支付宝app支付相关参数

目录

微信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,的存放路径

商户后台自己点击下载即可,什么是商户API证书?如何获取商户API证书?

开发所需的接口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

登陆支付宝开放平台支付宝开放平台查看

应用私钥appPrivateKey

小程序文档 - 支付宝文档中心,设置接口加签方式过程中生成的私钥

应用公钥证书appCertPath

支付宝公钥证书alipayCertPath

支付宝根证书alipayRootCertPath

支付宝文档参考链接:小程序文档 - 支付宝文档中心

按照文档一步步就可以生成公钥证书及私钥等相关文件

在这里插入图片描述

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 {
		//构造client
		CertAlipayRequest 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 {
		// 构造client
		CertAlipayRequest 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 {
        //这里和普通的接口调用不同,使用的是sdkExecute
        AlipayTradeAppPayResponse 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")

  • 3
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
微信小程序无法直接调用支付宝接口,需要通过支付宝开放平台提供的接口进行调用。以下是简单的示例代码: 1. 在支付宝开放平台注册并创建应用,获取到应用的 App ID 和私钥。 2. 在微信小程序中发起请求,将用户的订单信息传递给后端。 3. 后端使用私钥对订单信息进行签名,并将签名后的数据传递给支付宝接口。 4. 支付宝接口返回支付页面的 URL,后端将其返回给小程序。 5. 小程序使用 web-view 组件加载支付页面。 以下是后端示例代码(使用 Node.js): ```javascript const crypto = require('crypto'); const request = require('request'); const appId = 'YOUR_APP_ID'; const privateKey = 'YOUR_PRIVATE_KEY'; const signData = (data) => { const sign = crypto.createSign('RSA-SHA256'); sign.write(data); sign.end(); return sign.sign(privateKey, 'base64'); }; const createOrder = (orderInfo, callback) => { const sign = signData(orderInfo); const formData = { app_id: appId, biz_content: orderInfo, sign_type: 'RSA2', sign, }; request.post({ url: 'https://openapi.alipay.com/gateway.do', form: formData, }, (err, response, body) => { if (err) { callback(err); return; } const result = JSON.parse(body); if (result.code !== '10000') { callback(result.msg); return; } callback(null, result.alipay_trade_wap_pay_response.out_trade_no); }); }; module.exports = createOrder; ``` 以上代码中的 `createOrder` 函数用于创建订单,接受一个包含订单信息的 JSON 对象作为参数,并通过支付宝接口返回订单号。其中 `signData` 函数用于对订单信息进行签名,`request` 库用于简化 HTTP 请求的操作。 在小程序中,需要使用 `web-view` 组件将支付页面加载进来,示例代码如下: ```xml <web-view src="{{payUrl}}" bindmessage="onMessage"></web-view> ``` 其中 `payUrl` 是后端返回的支付页面 URL,`onMessage` 是一个事件处理函数,用于监听支付结果的回调。在支付页面中,用户完成支付后会自动跳转回小程序,同时会发送消息给小程序,消息的内容包含支付结果信息。以下是 `onMessage` 函数的示例代码: ```javascript onMessage(e) { const data = JSON.parse(e.detail.data); if (data.status === 'success') { // 支付成功 } else { // 支付失败 } } ``` 以上是简单的示例代码,实际应用中还需要考虑更多的细节和安全性问题。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

瑶山

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值