package com.stylefeng.guns.modular.api;
|
|
import com.alibaba.fastjson.JSONObject;
|
import com.stylefeng.guns.core.base.controller.BaseController;
|
import com.stylefeng.guns.core.base.tips.ErrorTip;
|
import com.stylefeng.guns.core.shiro.ShiroKit;
|
import com.stylefeng.guns.core.shiro.ShiroUser;
|
import com.stylefeng.guns.core.util.JwtTokenUtil;
|
import com.stylefeng.guns.core.util.PaymentTypeEnum;
|
import com.stylefeng.guns.core.util.ToolUtil;
|
import com.stylefeng.guns.modular.cloudPayment.example.BalanceAcctExample;
|
import com.stylefeng.guns.modular.cloudPayment.example.DepositExample;
|
import com.stylefeng.guns.modular.cloudPayment.example.MchApplicationExample;
|
import com.stylefeng.guns.modular.cloudPayment.example.RefundExample;
|
import com.stylefeng.guns.modular.cloudPayment.req.BalanceAcctReq;
|
import com.stylefeng.guns.modular.cloudPayment.req.DepositReq;
|
import com.stylefeng.guns.modular.system.dao.UserMapper;
|
import com.stylefeng.guns.modular.system.model.User;
|
import com.stylefeng.guns.modular.system.service.ITCompanyService;
|
import com.stylefeng.guns.modular.system.service.ITDriverService;
|
import com.unionpay.upyzt.exception.UpyztException;
|
import com.unionpay.upyzt.resp.BalanceAcctListResp;
|
import com.unionpay.upyzt.resp.BalanceAcctResp;
|
import com.unionpay.upyzt.resp.DepositResp;
|
import com.unionpay.upyzt.resp.MchApplicationResp;
|
import io.swagger.annotations.ApiOperation;
|
import org.apache.shiro.authc.SimpleAuthenticationInfo;
|
import org.apache.shiro.authc.UsernamePasswordToken;
|
import org.apache.shiro.authc.credential.HashedCredentialsMatcher;
|
import org.apache.shiro.crypto.hash.Md5Hash;
|
import org.apache.shiro.util.ByteSource;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.web.bind.annotation.*;
|
|
import javax.annotation.Resource;
|
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletResponse;
|
import java.text.SimpleDateFormat;
|
import java.util.Date;
|
import java.util.HashMap;
|
import java.util.Map;
|
import java.util.Objects;
|
|
/**
|
* 接口控制器提供
|
*
|
* @author stylefeng
|
* @Date 2018/7/20 23:39
|
*/
|
@RestController
|
@RequestMapping("/gunsApi")
|
public class ApiController extends BaseController {
|
|
@Autowired
|
private UserMapper userMapper;
|
|
@Resource
|
private ITCompanyService companyMapper;
|
|
@Autowired
|
private ITDriverService driverService;
|
|
/**
|
* api登录接口,通过账号密码获取token
|
*/
|
@RequestMapping("/auth")
|
public Object auth(@RequestParam("username") String username,
|
@RequestParam("password") String password) {
|
|
//封装请求账号密码为shiro可验证的token
|
UsernamePasswordToken usernamePasswordToken = new UsernamePasswordToken(username, password.toCharArray());
|
|
//获取数据库中的账号密码,准备比对
|
User user = userMapper.getByAccount(username);
|
|
String credentials = user.getPassword();
|
String salt = user.getSalt();
|
ByteSource credentialsSalt = new Md5Hash(salt);
|
SimpleAuthenticationInfo simpleAuthenticationInfo = new SimpleAuthenticationInfo(
|
new ShiroUser(), credentials, credentialsSalt, "");
|
|
//校验用户账号密码
|
HashedCredentialsMatcher md5CredentialsMatcher = new HashedCredentialsMatcher();
|
md5CredentialsMatcher.setHashAlgorithmName(ShiroKit.hashAlgorithmName);
|
md5CredentialsMatcher.setHashIterations(ShiroKit.hashIterations);
|
boolean passwordTrueFlag = md5CredentialsMatcher.doCredentialsMatch(
|
usernamePasswordToken, simpleAuthenticationInfo);
|
|
if (passwordTrueFlag) {
|
HashMap<String, Object> result = new HashMap<>();
|
result.put("token", JwtTokenUtil.generateToken(String.valueOf(user.getId())));
|
return result;
|
} else {
|
return new ErrorTip(500, "账号密码错误!");
|
}
|
}
|
@GetMapping("/auth1")
|
public Object auth1( String number) {
|
// 6207982267191357985
|
try {
|
BalanceAcctReq balanceAcctReq = new BalanceAcctReq();
|
balanceAcctReq.setMchId(number);
|
BalanceAcctListResp balanceAcctListResp = BalanceAcctExample.retrieveByUserId(balanceAcctReq);
|
return balanceAcctListResp;
|
} catch (UpyztException e) {
|
e.printStackTrace();
|
return number;
|
}
|
|
|
}
|
@GetMapping("/auth11")
|
public Object auth11( String number) {
|
// 6207982267191357985
|
try {
|
BalanceAcctReq balanceAcctReq = new BalanceAcctReq();
|
balanceAcctReq.setCusId(number);
|
BalanceAcctListResp balanceAcctListResp = BalanceAcctExample.retrieveByUserId(balanceAcctReq);
|
return balanceAcctListResp;
|
} catch (UpyztException e) {
|
e.printStackTrace();
|
return number;
|
}
|
}
|
|
@GetMapping("/auth2")
|
public Object auth2() {
|
try {
|
companyMapper.updateMoney();
|
return "ok";
|
}catch (Exception e){
|
e.printStackTrace();
|
return e;
|
}
|
|
}
|
|
@GetMapping(value = "/auth22")
|
// @ApiOperation(value = "支付充值查询", tags = {"支付充值查询"}, notes = "")
|
// @ApiImplicitParams({
|
// @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
|
// })
|
public Object auth22(String number,String no,Integer money) throws UpyztException {
|
return RefundExample.runDemos(number,no,money);
|
|
|
// DepositResp balanceAcctResp = null;
|
// try {
|
// balanceAcctResp = DepositExample.retrieveById(number);
|
//// balanceAcctResp = DepositExample.retrieveById("2008429872055963229");
|
// System.err.println(balanceAcctResp);
|
// } catch (UpyztException e) {
|
// System.out.println("电子账簿查询失败:{}"+e.getMessage());
|
// e.printStackTrace();
|
// }
|
// System.out.println("电子账簿查询完成=========:{}"+balanceAcctResp);
|
|
|
|
// BalanceAcctListResp balanceAcctListResp = null;
|
// try {
|
// BalanceAcctReq balanceAcctReq = new BalanceAcctReq();
|
// balanceAcctReq.setMchId("1008427961477222943");
|
// balanceAcctListResp = BalanceAcctExample.retrieveByUserId(balanceAcctReq);
|
// System.err.println(balanceAcctListResp);
|
// } catch (UpyztException e) {
|
// System.err.println("电子账簿查询失败:{}"+e.getMessage());
|
// e.printStackTrace();
|
// }
|
// System.err.println("电子账簿查询完成=========:{}"+balanceAcctListResp);
|
// return balanceAcctListResp;
|
|
|
// DepositReq depositReq = new DepositReq();
|
// depositReq.setOutOrderNo(ToolUtil.getRandomString(32));
|
// //-
|
// depositReq.setAmount(1); // 支付金额
|
// depositReq.setBalanceAcctId("2007907058462291527");
|
// depositReq.setDepositType("1");
|
// depositReq.setPaymentType(PaymentTypeEnum.CUP_APP.getCode());
|
// //-
|
// depositReq.setPaymentTradeNo("88890525-135");
|
// depositReq.setPaymentSucceededAt(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ").format(new Date()));
|
// //-
|
// depositReq.setOrderNo("88890525-135");
|
// depositReq.setOrderAmount(1L);
|
// depositReq.setProductName("充值金额");
|
// depositReq.setProductCount(1);
|
// depositReq.setNotifyUrl("http://zhentonggongsi.com:8010/api/placeOrder/notifyUrlOne");
|
// DepositResp depositResp = null;
|
// try {
|
// depositResp = DepositExample.create(depositReq);
|
// } catch (UpyztException e) {
|
// System.err.println(e.getMessage());
|
// e.printStackTrace();
|
// }
|
// System.err.println(depositResp);
|
// System.err.println("支付充值成功:{}"+depositResp);
|
// return depositResp;
|
|
}
|
|
// @ResponseBody
|
// @RequestMapping(value = "/addTodayActivity", method = RequestMethod.POST)
|
// @ApiOperation(value = "生成当天的司机活动", tags = {"生成当天的司机活动"}, notes = "")
|
// public void addTodayActivity(){
|
// try {
|
// driverService.addTodayActivity();
|
// } catch (Exception e) {
|
// throw new RuntimeException(e);
|
// }
|
// }
|
|
|
@RequestMapping(value = "/notify",method = RequestMethod.POST)
|
public void notify(JSONObject jsonObject,HttpServletRequest request, HttpServletResponse resp) {
|
|
// 获取参数
|
System.err.println("回调参数:"+jsonObject);
|
// Map<String, String[]> parameterMap = request.getParameterMap();
|
if(Objects.isNull(jsonObject)){
|
resp.setStatus(500);
|
return;
|
}
|
String event_type = jsonObject.getString("event_type");
|
if("trade_result".equals(event_type)){
|
// 交易结果通知
|
JSONObject event_data = jsonObject.getJSONObject("event_data");
|
Integer trade_type = event_data.getInteger("trade_type");
|
String out_order_no = event_data.getString("out_order_no");
|
String status = event_data.getString("status");
|
if("succeeded".equals(status)){
|
if(20 == trade_type){
|
// 支付充值
|
}
|
if(25 == trade_type){
|
// 可提现支付充值
|
}
|
if(30 == trade_type){
|
// 提现
|
}
|
if(51 == trade_type){
|
// 分账
|
}
|
}
|
}
|
//返回给银联服务器http 200 状态码
|
resp.setStatus(200);
|
}
|
/**
|
* 测试接口是否走鉴权
|
*/
|
@RequestMapping(value = "/test", method = RequestMethod.POST)
|
public Object test() {
|
return SUCCESS_TIP;
|
}
|
|
}
|