com.foxinmy.weixin4j.payment.mch.APPPayRequest Maven / Gradle / Ivy
package com.foxinmy.weixin4j.payment.mch;
import java.util.HashMap;
import java.util.Map;
import com.foxinmy.weixin4j.model.WeixinPayAccount;
import com.foxinmy.weixin4j.payment.PayRequest;
import com.foxinmy.weixin4j.type.SignType;
import com.foxinmy.weixin4j.type.TradeType;
import com.foxinmy.weixin4j.util.DigestUtil;
import com.foxinmy.weixin4j.util.MapUtil;
/**
* APP支付
*
* @className APPPayRequest
* @author jinyu([email protected])
* @date 2015年12月25日
* @since JDK 1.6
* @see com.foxinmy.weixin4j.payment.mch.PrePay
* @see com.foxinmy.weixin4j.payment.PayRequest
* @see APP支付
* @deprecated 迁移到子模块weixin4j-pay
*/
@Deprecated
public class APPPayRequest extends AbstractPayRequest {
public APPPayRequest(String prePayId, WeixinPayAccount payAccount) {
super(prePayId, payAccount);
}
@Override
public TradeType getPaymentType() {
return TradeType.APP;
}
/**
* 只做查看之用,请不要尝试作为支付请求
*/
@Override
public PayRequest toRequestObject() {
PayRequest payRequest = new PayRequest(getPaymentAccount().getId(), "Sign=WXPay");
payRequest.setPartnerId(getPaymentAccount().getMchId());
payRequest.setPrepayId(getPrePayId());
Map map = new HashMap();
map.put("appid", payRequest.getAppId());
// 因为partnerid和prepayid在PayRequest类中是不进行序列化的
map.put("partnerid", payRequest.getPartnerId());
map.put("prepayid", payRequest.getPrepayId());
map.put("package", payRequest.getPackageInfo());
map.put("timestamp", payRequest.getTimeStamp());
map.put("noncestr", payRequest.getNonceStr());
String sign = DigestUtil.MD5(
String.format("%s&key=%s", MapUtil.toJoinString(map, false, true), getPaymentAccount().getPaySignKey()))
.toUpperCase();
payRequest.setPaySign(sign);
payRequest.setSignType(SignType.MD5);
return payRequest;
}
@Override
public String toRequestString() {
PayRequest payRequest = toRequestObject();
StringBuilder content = new StringBuilder();
content.append("");
content.append(String.format(" ", payRequest.getAppId()));
content.append(String.format(" ", payRequest.getPartnerId()));
content.append(String.format(" ", payRequest.getPrepayId()));
content.append(String.format(" ", payRequest.getPackageInfo()));
content.append(String.format(" ", payRequest.getNonceStr()));
content.append(String.format(" ", payRequest.getTimeStamp()));
content.append(String.format(" ", payRequest.getPaySign()));
content.append(" ");
return content.toString();
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy