统一下单接口
/**
* pc端扫码支付入口
* @param toTopicId 帖子id
* @param money 打赏多少钱
* @param itype 帖子类型
* @param flag 支付宝打赏还是微信打赏
* @return
*/
public Object pcAliCreate(String toTopicId,int money,int itype,byte flag){
int uid = Toolkit.uid();
// 没登陆也可以打赏
NutMap nutMap = createPayment(money,itype,toTopicId,flag,uid);
if (nutMap.getInt("ok") == 0){
return nutMap;
}
PayMent payMent = (PayMent) nutMap.get("payMent");
if (flag == PayType.al.getIndex()){
// 支付宝支付
Map<String, String> sParaTemp = new HashMap<String, String>();
sParaTemp.put("service", AlipayConfig.service);
sParaTemp.put("partner", AlipayConfig.partner);
sParaTemp.put("seller_id", AlipayConfig.seller_id);
sParaTemp.put("_input_charset", AlipayConfig.input_charset);
sParaTemp.put("payment_type", AlipayConfig.payment_type);
sParaTemp.put("notify_url", AlipayConfig.notify_url);
sParaTemp.put("return_url", AlipayConfig.return_url);
sParaTemp.put("anti_phishing_key", AlipayConfig.anti_phishing_key);
sParaTemp.put("exter_invoke_ip", AlipayConfig.exter_invoke_ip);
String name = "打赏";
// String aa = "";
try {
String code = getEncoding(name);
// Charset.defaultCharset();
// String code = Utils.codeString(name);
log.debug("PayService|pcAliCreate|code="+code);
// name = new String(name.getBytes("ISO-8859-1"),"UTF-8");
sParaTemp.put("out_trade_no",new String(payMent.getOut_trade_no().getBytes("ISO-8859-1"),"UTF-8") );
sParaTemp.put("subject", new String(name.getBytes(code),"UTF-8"));//订单名称
sParaTemp.put("total_fee", new String("0.01".getBytes("ISO-8859-1"),"UTF-8"));
}catch (Exception e){
e.printStackTrace();
}
log.debug("PayService|pcAliCreate|sParaTemp="+Json.toJson(sParaTemp));
String sHtmlText = AlipaySubmit.buildRequest(sParaTemp,"get","确认");
payMent.setTrade_no("");
dao.insert(payMent);
return sHtmlText;
}else if (flag == PayType.wx.getIndex()){
// 2017/5/22 微信支付 调用统一下单
String body = "打赏";
String ip = IPUtil.getRemoteAddr();
log.debug("PayService|pcAliCreate|ip="+ip);
if (ip.equals("0:0:0:0:0:0:0:1")){
// 测试时会走这里
ip = "127.0.0.1";
}
String random = RandomStringGenerator.getRandomStringByLength(32);
// conf.get("forum.project.url") 服务器地址
// conf.get("forum.project.name") 工程名
String url = conf.get("forum.project.url")+"/"+conf.get("forum.project.name")+"/wx/pay/pc/notify";
Map map = getWxSign(payMent.getOut_trade_no(),1, "星空联盟打赏",ip,"NATIVE",random,new Date(),url);
// Map map = getWxSign(payMent.getOut_trade_no(),1,body, ip);
String result_code = (String)map.get("result_code");
if (result_code == null || !result_code.equals("SUCCESS")){
return ServiceUtil.failed("微信下单失败").setv("map",map);
}
String return_code = (String)map.get("return_code");
if (return_code == null || !return_code.equals("SUCCESS")){
return ServiceUtil.failed("微信下单失败").setv("map",map);
}
payMent.setTrade_no((String) map.get("prepay_id"));
dao.insert(payMent);
log.debug("PayService|pcAliCreate|map="+Json.toJson(map));
return Json.toJson(map);
}
return null;
}