package com.brt.wal.web.controller;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.security.spec.AlgorithmParameterSpec;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.net.URLConnection;
import com.alibaba.fastjson.JSON;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.alibaba.fastjson.JSONObject;
import com.brt.wal.pojo.Device;
import com.brt.wal.pojo.User;
import com.brt.wal.pojo.Userhistory;
import com.brt.wal.service.DeviceService;
import com.brt.wal.service.UserHistroyService;
import com.brt.wal.wxpay.common.Configure;
import com.brt.wal.wxpay.common.HttpRequest;
import com.brt.wal.wxpay.common.MobiMessage;
import com.brt.wal.wxpay.common.RandomStringGenerator;
import com.brt.wal.wxpay.common.RefundRequest;
import com.brt.wal.wxpay.common.Signature;
import com.brt.wal.wxpay.model.OrderInfo;
import com.brt.wal.wxpay.model.OrderReturnInfo;
import com.brt.wal.wxpay.model.RefundReqData;
import com.brt.wal.wxpay.model.SignInfo;
import com.mysql.jdbc.StringUtils;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomDriver;
import sun.dc.DuctusRenderingEngine;
/**
*
* @ClassName: DeviceController
* @Description: TODO(查询锁状态、修改锁状态)
* @author WWM
* @date 2018年6月14日
*
*/
@Controller
@RequestMapping("/device")
public class DeviceController {
/**
*
* @Title: refund
* @Description: TODO(微信退款)
* @param @param request
* @param @return
* @param @throws Exception 参数
* @return JSONObject 返回类型
* @throws
*/
@RequestMapping("/refund")
@ResponseBody
public JSONObject refund(HttpServletRequest request) throws Exception {
JSONObject json = new JSONObject();
Userhistory history = new Userhistory();
String userId=request.getParameter("userId"); //获得用户主键
history.setRefund(Integer.parseInt(request.getParameter("refund"))); //归还
history.setDeviceId(request.getParameter("number"));
Userhistory h = historyService.find(history);
if(h==null){
json.put("return_msg", "该锁原已关闭");
json.put("return_code", "FAIL");
return json;
}
if(!userId.equals(h.getUserId())){
json.put("return_msg", "用户ID匹配不上");
json.put("return_code", "FAIL");
return json;
}
Integer totalFee = h.getDeposit();//获取支付金额
String outTradeNo=h.getTransaction_id();//获取商户订单号
Map<String, String> getMap = new HashMap<String, String>();
//获得当前目录
String path = request.getSession().getServletContext().getRealPath("/");
Date now = new Date();
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");//可以方便地修改日期格式
String outRefundNo = "NO" + dateFormat.format( now );
//获得退款的传入参数
//String transactionID = "4200000146201806274097780745";
//outTradeNo = "awpnnjmdoy8is1xr0fsthmkow1ri26d6";
Integer refundFee = totalFee;
//RefundReqData refundReqData = new RefundReqData(transactionID,outTradeNo,outRefundNo,totalFee,refundFee);
RefundReqData refundReqData = new RefundReqData();
refundReqData.setAppid(Configure.getAppID());
refundReqData.setMch_id(Configure.getMch_id());
refundReqData.setNonce_str(RandomStringGenerator.getRandomStringByLength(32));
refundReqData.setOut_trade_no(outTradeNo);
refundReqData.setOut_refund_no(outRefundNo);
refundReqData.setTotal_fee(totalFee);
refundReqData.setRefund_fee(refundFee);
refundReqData.setOp_user_id(Configure.getMch_id());
refundReqData.setNotify_url("https://weixin.qq.com/notify/");
String sign = Signature.getSign(refundReqData);//生成签名
refundReqData.setSign(sign);
String info = MobiMessage.RefundReqData2xml(refundReqData).replaceAll("__", "_");
try {
RefundRequest refundRequest = new RefundRequest();
String result = refundRequest.httpsRequest("https://api.mch.weixin.qq.com/secapi/pay/refund", info, path);
getMap = MobiMessage.parseXml(new String(result.toString().getBytes(), "utf-8"));
System.out.println(getMap+"............getMap");
json.put("return_msg", getMap.get("return_msg"));
json.put("return_code", getMap.get("return_code"));
json.put("outTradeNo", outTradeNo);
}catch(Exception e){
e.printStackTrace();
}
return json;
}
}
java微信退款
需积分: 9 84 浏览量
2018-07-05
10:58:14
上传
评论
收藏 5KB RAR 举报
一个帅的男人
- 粉丝: 10
- 资源: 4