package cc.mrbird.febs.pay.service.impl; import cc.mrbird.febs.common.entity.FebsResponse; import cc.mrbird.febs.pay.model.UnipayDto; import cc.mrbird.febs.pay.service.UnipayService; import cc.mrbird.febs.pay.util.HttpRequester; import cc.mrbird.febs.pay.util.HttpRespons; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import lombok.extern.slf4j.Slf4j; import org.apache.commons.codec.digest.DigestUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.io.IOException; import java.util.*; @Slf4j @Service public class UnipayServiceImpl implements UnipayService { public static final String notifyUrl = "http://47.111.90.145:8800/api/unipay/unipayCallBack"; @Override @Transactional public String unipay(UnipayDto unipayDto) { String key = "2e95f6a3e11e47fa8a4386d6aefe1735";/** md5密钥商户后台-商户中心-商户设置-密钥管理获取 必填!*/ Map map = new HashMap(); map.put("p0_Version", "1.0");/** 版本号 */ map.put("p1_MerchantNo", "888118000001971");/** 商户编号 */ map.put("p2_OrderNo", unipayDto.getOrderNo()); /**商户订单号*/ map.put("p3_Amount", unipayDto.getAmount().toString());/**订单金额*/ map.put("p4_Cur", "1"); /**交易币种 */ map.put("p5_ProductName", unipayDto.getProductName()); /** 商品名称 */ map.put("p9_NotifyUrl", notifyUrl); /** 服务器异步通知地址 */ map.put("q1_FrpCode", unipayDto.getFrpCode()); /** 交易类型*/ map.put("qa_TradeMerchantNo",unipayDto.getTradeMerchantNo()); /** 777开头的报备商户号 必填!*/ map.put("q7_AppId", "wx42ce0fbc27965fe9"); /** 777开头的报备商户号 必填!*/ String Strmap = createLinkStringByGet(map); // 签名 String sign = ""; sign = SignByMD5(Strmap, key); map.put("hmac", sign);/** 签名数据 */ System.out.println("发送:" + JSON.toJSONString(map).toString()); // post请求参数内容 HttpRequester hr = new HttpRequester(); HttpRespons HP = null; try { HP = hr.sendPost("https://www.joinpay.com/trade/uniPayApi.action", map); } catch (IOException e) { e.printStackTrace(); } System.out.println("接收返回参数:" + HP.getContent()); Boolean result = false; try { result = nosign(HP.getContent(), key); } catch (Exception e) { e.printStackTrace(); } if(result){ return HP.getContent(); }else{ return "fail"; } } //参数的拼接整理 private String createLinkStringByGet(Map params){ // TODO Auto-generated method stub List keys = new ArrayList(params.keySet()); Collections.sort(keys); String str1 =""; for(int i=0;i