141 lines
3.8 KiB
Java
141 lines
3.8 KiB
Java
package sc545.pay.main;
|
|
|
|
import java.util.HashMap;
|
|
import java.util.Map;
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
import org.springframework.web.bind.annotation.CrossOrigin;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
|
|
import sc545.pay.utils.DBUtil;
|
|
import sc545.pay.utils.GsonUtils;
|
|
import sc545.pay.utils.Utils;
|
|
|
|
|
|
|
|
|
|
@CrossOrigin(origins = "*", maxAge = 3600)
|
|
@RestController
|
|
public class MainController {
|
|
|
|
|
|
/**
|
|
* 获取付款码
|
|
* @param param
|
|
* @param request
|
|
* @param response
|
|
* @return
|
|
*/
|
|
@RequestMapping(value = "/createOrder", produces = "text/html;charset=UTF-8")
|
|
public String createOrder(
|
|
@RequestParam(required = false, defaultValue = "") String n,
|
|
@RequestParam(required = false, defaultValue = "") String t,
|
|
HttpServletRequest request,
|
|
HttpServletResponse response
|
|
) {
|
|
|
|
double num = Utils.getNumDouble(n);
|
|
if(num<0.01||num>2000) return "{\"errcode\":\"-1\",\"msg\":\"0<金额<2000\"}";
|
|
core core=new core();
|
|
HashMap<String, String> order = core.createOrder(num, t);
|
|
|
|
return GsonUtils.ObjectToJson(order);
|
|
}
|
|
|
|
|
|
/**
|
|
* 查询订单
|
|
* @param id
|
|
* @param request
|
|
* @param response
|
|
* @return
|
|
*/
|
|
@RequestMapping(value = "/queryOrder", produces = "text/html;charset=UTF-8")
|
|
public String queryOrder(
|
|
@RequestParam(required = false, defaultValue = "") String id,
|
|
HttpServletRequest request,
|
|
HttpServletResponse response
|
|
) {
|
|
|
|
|
|
core core=new core();
|
|
Map<String, Object> order = core.queryOrder(id);
|
|
|
|
return GsonUtils.ObjectToJson(order);
|
|
}
|
|
|
|
/**
|
|
* 查询支付是否已完成
|
|
* @param id
|
|
* @param request
|
|
* @param response
|
|
* @return
|
|
*/
|
|
@RequestMapping(value = "/queryPay", produces = "text/html;charset=UTF-8")
|
|
public String queryPay(
|
|
@RequestParam(required = false, defaultValue = "") String id,
|
|
HttpServletRequest request,
|
|
HttpServletResponse response
|
|
) {
|
|
|
|
|
|
core core=new core();
|
|
Map<String, Object> order = core.queryOrder(id);
|
|
|
|
if(order!=null){
|
|
if("3".equals(order.get("ostatus")+"")||"4".equals(order.get("ostatus")+"")) return "{\"msg\":\"已支付\"}";
|
|
else return "{\"msg\":\"未支付\"}";
|
|
}else{
|
|
return "{\"msg\":\"未支付\"}";
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 支付宝通知回调<br>
|
|
* 设置中的“应用网关”
|
|
* @param param
|
|
* @param request
|
|
* @param response
|
|
*/
|
|
@RequestMapping(value = "/alinotify", produces = "text/html;charset=UTF-8")
|
|
public void alinotify(
|
|
@RequestParam(required = false, defaultValue = "") Map<String, String> param,
|
|
HttpServletRequest request,
|
|
HttpServletResponse response
|
|
) {
|
|
|
|
DBUtil db = new DBUtil();
|
|
core core=new core();
|
|
|
|
//只有支付成功后,支付宝才会回调应用接口,可直接获取支付宝响应的参数
|
|
String order_id = param.get("out_trade_no");
|
|
int s =0;
|
|
String ss = param.get("trade_status");
|
|
if("WAIT_BUYER_PAY".equals(ss)) s=1;
|
|
else if("TRADE_CLOSED".equals(ss)) s=2;
|
|
else if("TRADE_SUCCESS".equals(ss)) s=3;
|
|
else if("TRADE_FINISHED".equals(ss)) s=4;
|
|
|
|
//检查数据库是否有本数据,有就修改,没有新增
|
|
int i = db.execSql("select * from _orders where out_trade_no = ?", new String[]{order_id});
|
|
if(i>0) core.updateOrder(order_id);
|
|
else{
|
|
db.execUpdate("insert into _orders(out_trade_no,trade_no,otitle,onum,ostatus,zfbuser,paynum,getnum,zfbuserid,getbody) "
|
|
+ "values("+order_id+",?,?,"+param.get("total_amount")+","+s+",?,"+param.get("buyer_pay_amount")+","+param.get("receipt_amount")+",?,?)", new String[]{param.get("trade_no"),param.get("subject"),param.get("buyer_logon_id"),param.get("buyer_id"),param.toString()});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|