Commit e0bcaadc by 彭祥礼

新增支付成功调用接口和订单详情页接口

parent 945e3c53
...@@ -9,14 +9,21 @@ import com.winsun.bean.*; ...@@ -9,14 +9,21 @@ import com.winsun.bean.*;
import com.winsun.mapper.*; import com.winsun.mapper.*;
import com.winsun.utils.*; import com.winsun.utils.*;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import net.sf.json.JSONObject;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.*; import java.util.*;
import java.util.concurrent.TimeUnit;
/** /**
* 兑换券校检 * 兑换券校检
...@@ -29,6 +36,7 @@ import java.util.*; ...@@ -29,6 +36,7 @@ import java.util.*;
@RequestMapping("/yxtCard") @RequestMapping("/yxtCard")
public class YxtCardController extends BaseController { public class YxtCardController extends BaseController {
private static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); private static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
private static SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
@Autowired @Autowired
private YxtCouponMapper yxtCouponMapper; private YxtCouponMapper yxtCouponMapper;
...@@ -40,7 +48,9 @@ public class YxtCardController extends BaseController { ...@@ -40,7 +48,9 @@ public class YxtCardController extends BaseController {
private YxtSalesLimitMapper yxtSalesLimitMapper; private YxtSalesLimitMapper yxtSalesLimitMapper;
@Autowired @Autowired
private YxtOrderDetailMapper yxtOrderDetailMapper; private YxtOrderDetailMapper yxtOrderDetailMapper;
@Autowired
private RedisTemplate redisTemplate;
private final double price = 25.0;
/** /**
* 进入院线通兑换券销售界面 * 进入院线通兑换券销售界面
* @return * @return
...@@ -58,82 +68,80 @@ public class YxtCardController extends BaseController { ...@@ -58,82 +68,80 @@ public class YxtCardController extends BaseController {
Map<String, Object> map = new Hashtable<>(); Map<String, Object> map = new Hashtable<>();
map.put("cardNum",cardNum); map.put("cardNum",cardNum);
map.put("salesNum",salesNum); map.put("salesNum",salesNum);
map.put("nMoney",25.0); map.put("price",price);
return ResponseData.success(map); return ResponseData.success(map);
} }
/** /**
* 测试时使用
* @param request
* @param response
* @throws UnsupportedEncodingException
*/
@RequestMapping(value = "/weixinAuthorizati")
public void weixinAuthorization(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException {
String requestURL = request.getContextPath().toString();
log.info(requestURL);
///redirect_uri=http://167460x6b0.51mypc.cn/ciop/forgerpw/callBackLogin
String redirect_uri = "http://192.168.1.165:3000/#/yxt/pay?userId=6399";
String url = "https://open.weixin.qq.com/connect/oauth2/authorize?";
url += "appid=" + WxConfig.APPID;
url += "&redirect_uri=" + URLEncoder.encode("http://167460x6b0.51mypc.cn/ciop/forgerpw/callBackLogin", "UTF-8");//此处和微信回调用的域名相同
url += "&response_type=code&scope=snsapi_userinfo&state=frommenu#wechat_redirect";
try {
response.sendRedirect(url);
} catch (Exception e) {
log.error("微信授权异常"+ e.getMessage(),e);
}
}
/**
* 进入院线通实体票下单界面 * 进入院线通实体票下单界面
* @return * @return
*/ */
@RequestMapping("/enterPay") @RequestMapping("/enterPay")
public ResponseData<String> enterPay(){ public ResponseData<Map<String,Object>> enterPay(String code) throws Exception{
/*String code = request.getParameter("code");
Map<String,Object> objectMap = new HashMap<>();
String result = WxInterfacesUtil.getAccess_tokenByCode(code); String result = WxInterfacesUtil.getAccess_tokenByCode(code);
String openIdt = redisTemplate.opsForValue().get("openid").toString();
if (StringUtils.isNotBlank(result)) { if (StringUtils.isNotBlank(result)) {
JSONObject obj = JSONObject.fromObject(result); JSONObject obj = JSONObject.fromObject(result);
String openId = String.valueOf(obj.get("openid")); String openId = String.valueOf(obj.get("openid"));
// code重复使用时,从session拿出第一次保存openId赋予openId // code重复使用时,从session拿出第一次保存openId赋予openId
if("null".equals(openId) && !"null".equals(String.valueOf(request.getSession().getAttribute("openId")))){ if("null".equals(openId) && !"null".equals(openIdt)){
openId = String.valueOf(request.getSession().getAttribute("openId")); openId = openIdt;
} }
// code重复使用时,openId为"null",不更新session // code重复使用时,openId为"null",不更新session
if(!"null".equals(openId)){ if(!"null".equals(openId)){
request.getSession().setAttribute("openId", openId); redisTemplate.opsForValue().set("openid", openId);//设置不过期
//redisTemplate.opsForValue().set("openid", openId, 1200, TimeUnit.MINUTES);
} }
request.setAttribute("openId", openId); objectMap.put("openId", openId);
System.out.println("openId:" +openId); log.info("openId:" +openId);
}*/
String openId = "isOk";
return ResponseData.success(openId);
}
/**
* 获取用户地址
* @return
*/
@RequestMapping("/getUserAddress")
public ResponseData<List<YxtAddress>> getUserAddress(@RequestParam("userId") String userId,@RequestParam("addressId") String addressId){
Wrapper<YxtAddress> wrapper = new EntityWrapper<>();
if(StringUtils.isNotBlank(addressId)){
wrapper.eq(StringUtils.isNotBlank(userId),"id",addressId);
}else{
wrapper.eq("user_id",userId);
} }
List<YxtAddress> list = yxtAddressMapper.selectList(wrapper);
return ResponseData.success(list); if(!"null".equals(openIdt)){
objectMap.put("openId", openIdt);
}
return ResponseData.success(objectMap);
} }
/** /**
* 获取用户地址 * 支付界面初始化
* @return
*/ */
@RequestMapping("/addAddress") @RequestMapping("getJsapiSign")
public ResponseData<List<YxtAddress>> addAddress(@RequestParam("address") String address){ public ResponseData<Map<String,Object>> getJsapiSign(HttpServletRequest request){
HashMap hashMap = JSON.parseObject(address, HashMap.class); // 加密参数
YxtAddress yxtAddress = new YxtAddress(); String url = "http://" + request.getServerName()+request.getRequestURI();
String userId = hashMap.get("userId").toString(); Map<String,Object> objectMap = null;
yxtAddress.setUserId(userId); try{
String consignee = hashMap.get("consignee").toString(); objectMap = new WxInterfacesUtil().getJspaiSign(url);
if(StringUtils.isBlank(consignee)){ objectMap.put("appid", WxConfig.APPID);
return ResponseData.error("收货人不能为空!!!"); }catch(Exception e){
} e.printStackTrace();
yxtAddress.setConsignee(consignee);
String phone = hashMap.get("phone").toString();
if(StringUtils.isBlank(phone)){
return ResponseData.error("联系电话不能为空!!!");
}
yxtAddress.setPhone(phone);
String area = hashMap.get("area").toString();
if(StringUtils.isBlank(area)){
return ResponseData.error("地址不能为空!!!");
}
yxtAddress.setArea(area);
yxtAddress.setDetailAddress(hashMap.get("detailAddress").toString());
yxtAddress.setUpdateDate(new Date());
Integer num = yxtAddressMapper.insert(yxtAddress);
if(num==1){
return ResponseData.success();
} }
return ResponseData.error("新增地址失败!!!"); return ResponseData.success(objectMap);
} }
/** /**
* 下单新增订单 * 下单新增订单
...@@ -141,15 +149,20 @@ public class YxtCardController extends BaseController { ...@@ -141,15 +149,20 @@ public class YxtCardController extends BaseController {
*/ */
@RequestMapping("/addYxtOrder") @RequestMapping("/addYxtOrder")
public ResponseData<Map<String,Object>> addYxtOrder(@RequestParam("order") String order){ public ResponseData<Map<String,Object>> addYxtOrder(@RequestParam("order") String order){
Map<String,Object> objectMap = new Hashtable<>(); Map<String,Object> objectMap = new Hashtable<>();
YxtOrder yxtOrderTemp = new YxtOrder();
List<YxtCoupon> coupIds = new ArrayList<>();
List<YxtOrderDetail> detailList = new ArrayList<>();
String msg = "";
try { try {
//目前可购买兑换券数量 //目前可购买兑换券数量
int totalNums = returnCardNum(); int totalNums = returnCardNum();
YxtOrder yxtOrder = JSON.parseObject(order, YxtOrder.class); YxtOrder yxtOrder = JSON.parseObject(order, YxtOrder.class);
String uuid = UUID.randomUUID().toString();
String orderNum = "YXT0018"+ ProduceIdUtil.getId(); String orderNum = "YXT0018"+ ProduceIdUtil.getId();
yxtOrder.setOrderNum(orderNum); yxtOrder.setOrderNum(orderNum);
Integer goodsNum = yxtOrder.getGoodsNum(); Integer goodsNum = yxtOrder.getGoodsNum();
redisTemplate.opsForValue().set("goodsNum",goodsNum.toString(),30, TimeUnit.MINUTES);
String orderType = yxtOrder.getOrderType(); String orderType = yxtOrder.getOrderType();
if(orderType.equals("实体订单")){ if(orderType.equals("实体订单")){
//快递状态(0:无须快递,1待寄出:,2:寄出,3:已寄出) //快递状态(0:无须快递,1待寄出:,2:寄出,3:已寄出)
...@@ -171,50 +184,61 @@ public class YxtCardController extends BaseController { ...@@ -171,50 +184,61 @@ public class YxtCardController extends BaseController {
dayNum = salesLimit.getSalesNum(); dayNum = salesLimit.getSalesNum();
} }
Integer num0 = yxtOrderMapper.insert(yxtOrder); Integer num0 = yxtOrderMapper.insert(yxtOrder);
YxtOrder yxtOrder1 = getYxtOrder(yxtOrder.getUserId(),yxtOrder.getOrderNum()); yxtOrderTemp = getYxtOrder(yxtOrder.getUserId(),yxtOrder.getOrderNum());
redisTemplate.opsForValue().set("yxtOrderId",yxtOrderTemp.getId().toString(),30, TimeUnit.MINUTES);
Integer residuNum = 5 - dayNum; Integer residuNum = 5 - dayNum;
if("实体订单".equals(orderType)){ if("实体订单".equals(orderType)){
// 快递订单不需分配兑换券账号和密码,由快递寄出 // 快递订单不需分配兑换券账号和密码,由快递寄出
if(num0==1){ if(num0==1){
objectMap.put("yxtOrder",yxtOrder1); objectMap.put("yxtOrder",yxtOrderTemp);
return ResponseData.success(objectMap); return ResponseData.success(objectMap);
} }
}else{ }else{
if((dayNum + goodsNum) > 5){ if(null != yxtOrderTemp){
yxtOrderMapper.deleteById(yxtOrder1.getId()); if((dayNum + goodsNum) > 5){
return ResponseData.error("每人每天限购5张,目前可购买数量为"+ residuNum +"!"); yxtOrderMapper.deleteById(yxtOrderTemp.getId());
}else{ return ResponseData.error("每人每天限购5张,目前可购买数量为"+ residuNum +"!");
if(totalNums < goodsNum && "电子订单".equals(orderType)){ }else{
yxtOrderMapper.deleteById(yxtOrder1.getId()); if(totalNums < goodsNum && "电子订单".equals(orderType)){
return ResponseData.error("可购买的兑换券数量不足,目前兑换券数量为"+ totalNums +";请刷新下单界面,重新购买!"); yxtOrderMapper.deleteById(yxtOrderTemp.getId());
return ResponseData.error("可购买的兑换券数量不足,目前兑换券数量为"+ totalNums +";请刷新下单界面,重新购买!");
}
} }
}
if(null != yxtOrder1){
Wrapper<YxtCoupon> couponWrapper = new EntityWrapper<>(); Wrapper<YxtCoupon> couponWrapper = new EntityWrapper<>();
couponWrapper.eq("state", "1"); couponWrapper.eq("state", "1");
couponWrapper.eq("shelf_state", "1"); couponWrapper.eq("shelf_state", "1");
List<YxtCoupon> couponList = yxtCouponMapper.selectList(couponWrapper); List<YxtCoupon> couponList = yxtCouponMapper.selectList(couponWrapper);
List<YxtCoupon> coupIds = new ArrayList<>(); int count = goodsNum;
for (YxtCoupon yxtCoupon : couponList) { for (YxtCoupon yxtCoupon : couponList) {
coupIds.add(yxtCoupon); coupIds.add(yxtCoupon);
count--;
if(count == 0){
break;
}
} }
List<YxtCoupon> yxtCoupons = new ArrayList<>(); List<YxtCoupon> yxtCoupons = new ArrayList<>();
int num1 = 0; int num1 = 0;
int num2 = 0; int count0 = 0;
for (YxtCoupon coup : coupIds) { for (YxtCoupon coup : coupIds) {
num2++; count0++;
if(num2 > totalNums){ if(count0 > totalNums){
break; break;
} }
yxtCoupons.add(coup); yxtCoupons.add(coup);
YxtOrderDetail detail = new YxtOrderDetail(); YxtOrderDetail detail = new YxtOrderDetail();
detail.setYxtId(coup.getId()); detail.setYxtId(coup.getId());
detail.setOrderId(yxtOrder1.getId()); detail.setOrderId(yxtOrderTemp.getId());
detailList.add(detail);
num1 += yxtOrderDetailMapper.insert(detail); num1 += yxtOrderDetailMapper.insert(detail);
} }
// 添加兑换券到订单详情后,更新兑换券状态,不允许再次购买 // 添加兑换券到订单详情后,更新兑换券状态,不允许再次购买
if(num1 == totalNums){ if(num1 == goodsNum){
//清空
while (redisTemplate.opsForList().size("yxtCouponList") > 0){
redisTemplate.opsForList().leftPop("yxtCouponList");
}
//存储
redisTemplate.opsForList().rightPushAll("yxtCouponList",yxtCoupons);
for (YxtCoupon coup : yxtCoupons) { for (YxtCoupon coup : yxtCoupons) {
Wrapper<YxtCoupon> yxtCouponWrapper = new EntityWrapper<>(); Wrapper<YxtCoupon> yxtCouponWrapper = new EntityWrapper<>();
yxtCouponWrapper.eq("id",coup.getId()); yxtCouponWrapper.eq("id",coup.getId());
...@@ -224,21 +248,23 @@ public class YxtCardController extends BaseController { ...@@ -224,21 +248,23 @@ public class YxtCardController extends BaseController {
} }
objectMap.put("yxtCoupons",yxtCoupons); objectMap.put("yxtCoupons",yxtCoupons);
}else{ }else{
return ResponseData.error("添加订单详情失败"); msg = "添加订单详情失败";
} }
}else{ }else{
return ResponseData.error("获取新增订单的信息失败"); msg = "获取新增订单的信息失败";
} }
if(num0==1){ if(num0==1){
objectMap.put("yxtOrder",yxtOrder1); objectMap.put("yxtOrder",yxtOrderTemp);
return ResponseData.success(objectMap); return ResponseData.success(objectMap);
}else{
msg = "院线通下单失败!!!";
} }
} }
}catch (Exception e){ }catch (Exception e){
log.info(e.getMessage()); e.printStackTrace();
return ResponseData.error("院线通下单失败!!!"); yxtOrderMapper.deleteById(yxtOrderTemp.getId());
} }
return ResponseData.error("院线通下单失败!!!"); return ResponseData.error(msg);
} }
/** /**
...@@ -292,7 +318,7 @@ public class YxtCardController extends BaseController { ...@@ -292,7 +318,7 @@ public class YxtCardController extends BaseController {
String xmlStr = WXPayUtil.map2Xmlstring(map); String xmlStr = WXPayUtil.map2Xmlstring(map);
String url = "https://api.mch.weixin.qq.com/pay/unifiedorder"; String url = "https://api.mch.weixin.qq.com/pay/unifiedorder";
String result = HTTPSClient.sendPostXml(url, xmlStr); String result = HTTPSClient.sendPostXml(url, xmlStr);
System.out.println(result); log.info(result);
Map<String, Object> resultMap = WXPayUtil.xmlString2Map(result); Map<String, Object> resultMap = WXPayUtil.xmlString2Map(result);
long timeStamp = System.currentTimeMillis(); long timeStamp = System.currentTimeMillis();
...@@ -322,12 +348,44 @@ public class YxtCardController extends BaseController { ...@@ -322,12 +348,44 @@ public class YxtCardController extends BaseController {
jsonObject.put("package", packages); jsonObject.put("package", packages);
jsonObject.put("signType", "MD5"); jsonObject.put("signType", "MD5");
jsonObject.put("sign", secretSign); jsonObject.put("sign", secretSign);
return ResponseData.success(jsonObject); return ResponseData.success(jsonObject);
}catch(Exception e){ }catch(Exception e){
e.printStackTrace(); e.printStackTrace();
log.info(e.getMessage());
}
//预支付信息生成失败后回滚
String orderId = redisTemplate.opsForValue().get("yxtOrderId").toString();
if(StringUtils.isNotBlank(orderId)) {
yxtOrderMapper.deleteById(Integer.valueOf(orderId));
} }
return ResponseData.error(""); if(StringUtils.isNotBlank(orderId)){
Wrapper<YxtOrderDetail> detailWrapper = new EntityWrapper<>();
detailWrapper.eq("order_id",Integer.valueOf(orderId));
detailWrapper.eq("is_del",0);
detailWrapper.orderBy("id",false);
List<YxtOrderDetail> details = yxtOrderDetailMapper.selectList(detailWrapper);
Integer count = Integer.valueOf(redisTemplate.opsForValue().get("goodsNum").toString());
for (YxtOrderDetail detail1 : details) {
yxtOrderDetailMapper.deleteById(detail1.getId());
count--;
if(count == 0){
break;
}
}
}
//取出
List<YxtCoupon> yxtCouponList = redisTemplate.opsForList().range("yxtCouponList", 0, -1);
log.info(">>>>>>>>>>>>>>>list = {}", yxtCouponList.toString());
Iterator<YxtCoupon> it = yxtCouponList.iterator();
while(it.hasNext()){
YxtCoupon p = it.next();
Wrapper<YxtCoupon> yxtCouponWrapper = new EntityWrapper<>();
yxtCouponWrapper.eq("id",p.getId());
YxtCoupon coupon = new YxtCoupon();
coupon.setState(1);
yxtCouponMapper.update(coupon,yxtCouponWrapper);
}
return ResponseData.error("预支付信息生成失败!!!");
} }
/** /**
...@@ -349,17 +407,17 @@ public class YxtCardController extends BaseController { ...@@ -349,17 +407,17 @@ public class YxtCardController extends BaseController {
detailWrapper.eq("order_id",orderNum); detailWrapper.eq("order_id",orderNum);
List<YxtOrderDetail> list = yxtOrderDetailMapper.selectList(detailWrapper); List<YxtOrderDetail> list = yxtOrderDetailMapper.selectList(detailWrapper);
List<Integer> couponIds = null; List<Integer> couponIds = null;
List<Integer> ids = null; List<Integer> detailIds = null;
if(list.size()>0){ if(list.size()>0){
for (YxtOrderDetail detail : list) { for (YxtOrderDetail detail : list) {
couponIds.add(detail.getYxtId()); couponIds.add(detail.getYxtId());
ids.add(detail.getId()); detailIds.add(detail.getId());
} }
} }
YxtOrderDetail orderDetail = new YxtOrderDetail(); YxtOrderDetail orderDetail = new YxtOrderDetail();
orderDetail.setIsDel(1); orderDetail.setIsDel(1);
Wrapper<YxtOrderDetail> orderDetailWrapper = new EntityWrapper<>(); Wrapper<YxtOrderDetail> orderDetailWrapper = new EntityWrapper<>();
orderDetailWrapper.in("id",ids); orderDetailWrapper.in("id",detailIds);
yxtOrderDetailMapper.update(orderDetail,orderDetailWrapper); yxtOrderDetailMapper.update(orderDetail,orderDetailWrapper);
//修改院线通卡的状态 //修改院线通卡的状态
YxtCoupon coupon = new YxtCoupon(); YxtCoupon coupon = new YxtCoupon();
...@@ -386,6 +444,7 @@ public class YxtCardController extends BaseController { ...@@ -386,6 +444,7 @@ public class YxtCardController extends BaseController {
Map<String,Object> objectMap = new HashMap<>(); Map<String,Object> objectMap = new HashMap<>();
Wrapper<YxtOrder> orderWrapper = new EntityWrapper<>(); Wrapper<YxtOrder> orderWrapper = new EntityWrapper<>();
orderWrapper.eq("order_num",orderNum); orderWrapper.eq("order_num",orderNum);
orderWrapper.eq("state",3);
List<YxtOrder> orderList = yxtOrderMapper.selectList(orderWrapper); List<YxtOrder> orderList = yxtOrderMapper.selectList(orderWrapper);
List<Integer> couponIds = null; List<Integer> couponIds = null;
if(orderList.size()>0){ if(orderList.size()>0){
...@@ -408,7 +467,93 @@ public class YxtCardController extends BaseController { ...@@ -408,7 +467,93 @@ public class YxtCardController extends BaseController {
} }
/**
* 获取院线通订单详情
* @return
*/
@RequestMapping("getYxtOrderDetail")
public ResponseData<Map<String,Object>> getYxtOrderDetail(@RequestParam("orderNum") String orderNum){
Map<String,Object> objectMap = new HashMap<>();
if(StringUtils.isBlank(orderNum)){
return ResponseData.error("订单号不能为空!!!");
}
try{
Wrapper<YxtOrder> orderWrapper = new EntityWrapper<>();
orderWrapper.eq("order_num",orderNum);
YxtOrder order = yxtOrderMapper.selectList(orderWrapper).get(0);
objectMap.put("order", order);
if(StringUtils.isNotBlank(order.getAddressId().toString())){
YxtAddress address = yxtAddressMapper.selectById(order.getAddressId());
objectMap.put("address", address);
}
if(order.getOrderType().equals("电子订单")){
Wrapper<YxtOrderDetail> detailWrapper = new EntityWrapper<>();
detailWrapper.eq("order_id",order.getId());
List<YxtOrderDetail> detail = yxtOrderDetailMapper.selectList(detailWrapper);
List<Integer> cuponList = new ArrayList<>();
for (YxtOrderDetail orderDetail : detail) {
cuponList.add(orderDetail.getYxtId());
}
Wrapper<YxtCoupon> couponWrapper = new EntityWrapper<>();
couponWrapper.in("id",cuponList);
List<YxtCoupon> cardList = yxtCouponMapper.selectList(couponWrapper);
objectMap.put("cardList", cardList);
}
objectMap.put("price", price);
}catch(Exception e){
e.printStackTrace();
}
return ResponseData.success(objectMap);
}
/**
* 获取用户地址
* @return
*/
@RequestMapping("/getUserAddress")
public ResponseData<List<YxtAddress>> getUserAddress(@RequestParam("userId") String userId,@RequestParam("addressId") String addressId){
Wrapper<YxtAddress> wrapper = new EntityWrapper<>();
if(StringUtils.isNotBlank(addressId)){
wrapper.eq(StringUtils.isNotBlank(userId),"id",addressId);
}else{
wrapper.eq("user_id",userId);
}
List<YxtAddress> list = yxtAddressMapper.selectList(wrapper);
return ResponseData.success(list);
}
/**
* 添加用户地址
* @return
*/
@RequestMapping("/addAddress")
public ResponseData<List<YxtAddress>> addAddress(@RequestParam("address") String address){
HashMap hashMap = JSON.parseObject(address, HashMap.class);
YxtAddress yxtAddress = new YxtAddress();
String userId = hashMap.get("userId").toString();
yxtAddress.setUserId(userId);
String consignee = hashMap.get("consignee").toString();
if(StringUtils.isBlank(consignee)){
return ResponseData.error("收货人不能为空!!!");
}
yxtAddress.setConsignee(consignee);
String phone = hashMap.get("phone").toString();
if(StringUtils.isBlank(phone)){
return ResponseData.error("联系电话不能为空!!!");
}
yxtAddress.setPhone(phone);
String area = hashMap.get("area").toString();
if(StringUtils.isBlank(area)){
return ResponseData.error("地址不能为空!!!");
}
yxtAddress.setArea(area);
yxtAddress.setDetailAddress(hashMap.get("detailAddress").toString());
yxtAddress.setUpdateDate(new Date());
Integer num = yxtAddressMapper.insert(yxtAddress);
if(num==1){
return ResponseData.success();
}
return ResponseData.error("新增地址失败!!!");
}
// 返回目前可购买兑换券数量 // 返回目前可购买兑换券数量
public int returnCardNum(){ public int returnCardNum(){
Wrapper<YxtCoupon> couponWrapper = new EntityWrapper<>(); Wrapper<YxtCoupon> couponWrapper = new EntityWrapper<>();
......
package com.winsun.bean; package com.winsun.bean;
import com.alibaba.fastjson.annotation.JSONField;
import com.baomidou.mybatisplus.annotations.TableField; import com.baomidou.mybatisplus.annotations.TableField;
import com.baomidou.mybatisplus.annotations.TableId; import com.baomidou.mybatisplus.annotations.TableId;
import com.baomidou.mybatisplus.annotations.TableName; import com.baomidou.mybatisplus.annotations.TableName;
import com.baomidou.mybatisplus.enums.IdType; import com.baomidou.mybatisplus.enums.IdType;
import lombok.Data; import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;
import java.io.Serializable; import java.io.Serializable;
import java.util.Date; import java.util.Date;
...@@ -47,6 +49,8 @@ public class YxtCoupon implements Serializable { ...@@ -47,6 +49,8 @@ public class YxtCoupon implements Serializable {
*有效截止日期 *有效截止日期
*/ */
@TableField("validity_period") @TableField("validity_period")
@JSONField(format = "yyyy-MM-dd HH:mm:ss") //FastJson包使用注解
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date validityPeriod; private Date validityPeriod;
/** /**
*上架状态 1:已上架 2:已下架 *上架状态 1:已上架 2:已下架
......
package com.winsun.bean; package com.winsun.bean;
import com.alibaba.fastjson.annotation.JSONField;
import com.baomidou.mybatisplus.annotations.TableField; import com.baomidou.mybatisplus.annotations.TableField;
import com.baomidou.mybatisplus.annotations.TableId; import com.baomidou.mybatisplus.annotations.TableId;
import com.baomidou.mybatisplus.annotations.TableName; import com.baomidou.mybatisplus.annotations.TableName;
import com.baomidou.mybatisplus.enums.IdType; import com.baomidou.mybatisplus.enums.IdType;
import lombok.Data; import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;
import java.io.Serializable; import java.io.Serializable;
import java.util.Date; import java.util.Date;
...@@ -53,6 +55,8 @@ public class YxtOrder implements Serializable { ...@@ -53,6 +55,8 @@ public class YxtOrder implements Serializable {
*创建时间 *创建时间
*/ */
@TableField("update_date") @TableField("update_date")
@JSONField(format = "yyyy-MM-dd HH:mm:ss") //FastJson包使用注解
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date updateDate; private Date updateDate;
/** /**
*是否删除(1.已删除,0.不删除) *是否删除(1.已删除,0.不删除)
......
package com.winsun.utils;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import org.apache.http.HttpResponse;
import org.apache.http.ParseException;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.protocol.HTTP;
import org.apache.http.util.EntityUtils;
public class HttpService {
public static String sendPost(String url, String param) throws ParseException, IOException{
String responseString = "";
HttpPost httpPost = new HttpPost(url);
httpPost.setEntity(new StringEntity(param, HTTP.UTF_8));
HttpResponse httpResponse = new DefaultHttpClient().execute(httpPost);
try{
int statusCode = httpResponse.getStatusLine().getStatusCode();
if (statusCode == 200) {
responseString = EntityUtils.toString(httpResponse.getEntity());
}
}catch(Exception e){
e.printStackTrace();
}
return responseString;
}
public InputStream post1(String param, String urlStr) {
InputStream is = null;
try {
byte[] xmlData = param.getBytes("UTF-8");
URL url = new URL(urlStr);
URLConnection urlCon = url.openConnection();
urlCon.setDoOutput(false);
urlCon.setDoInput(true);
urlCon.setConnectTimeout(40000);
urlCon.setReadTimeout(40000);
urlCon.setUseCaches(false);
// urlCon.setRequestProperty("Content-Type", contentType);
// urlCon.setRequestProperty("Content-length",
// String.valueOf(xmlData.length));
// // urlCon.setFixedLengthStreamingMode(xmlData.length);
// DataOutputStream printout = new DataOutputStream(
// urlCon.getOutputStream());
// printout.write(xmlData);
// printout.flush();
// printout.close();
is = urlCon.getInputStream();
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
return is;
}
}
...@@ -9,7 +9,7 @@ public class WxConfig { ...@@ -9,7 +9,7 @@ public class WxConfig {
/**************公众号参数信息*************/ /**************公众号参数信息*************/
// 公众号appid 校园服务号 // 公众号appid 校园服务号
public static final String APPID = "wx0641dc1dc4d34384"; //public static final String APPID = "wx0641dc1dc4d34384";
// 公众号秘钥 secret 校园服务号 // 公众号秘钥 secret 校园服务号
public static final String APPSECRET = "3b43b46fc94d4e98588ee6ad992fa5c7"; public static final String APPSECRET = "3b43b46fc94d4e98588ee6ad992fa5c7";
...@@ -19,7 +19,7 @@ public class WxConfig { ...@@ -19,7 +19,7 @@ public class WxConfig {
public static final String NOTIFY_URL = "http://dianyuanjiangli.com/xyjl/yx/wxpay/yxt!payNotify.action"; public static final String NOTIFY_URL = "http://dianyuanjiangli.com/xyjl/yx/wxpay/yxt!payNotify.action";
// // 公众号appid 网讯测试服务号 // // 公众号appid 网讯测试服务号
// public static final String APPID = "wxfc18f5186b729d15"; public static final String APPID = "wxfc18f5186b729d15";
// //
// // 公众号秘钥 secret 网讯测试服务号 // // 公众号秘钥 secret 网讯测试服务号
// public static final String APPSECRET = "122278f3fb555468848ff040620505ad"; // public static final String APPSECRET = "122278f3fb555468848ff040620505ad";
......
package com.winsun.utils;
import net.sf.ehcache.Element;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.apache.http.ParseException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.redis.core.RedisTemplate;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.TimeUnit;
public class WxInterfacesUtil {
@Autowired
@Qualifier("redisStringTemplate")
private RedisTemplate redisTemplate;
/**
* 获取凭证
* @param grant_type 获取access_token填写client_credential
* @param appid 第三方用户唯一凭证
* @param secret 第三方用户唯一凭证密钥,既appsecret
* @return json token:获取到的凭证 expires_in:凭证有效时间,单位:秒
*/
public String getToken(String grant_type,String appid,String secret){
String result = null;
Element ele = null;//tokenCache.get("token_cache");
if(ele!=null){
result = (String)ele.getValue();
}else{
String url="https://api.weixin.qq.com/cgi-bin/token?grant_type="+grant_type+"&appid="+appid+"&secret="+secret;
String res = HTTPSClient.sendGet(url);
JSONObject jobj = JSONObject.fromObject(res);
if(jobj.has("access_token")){
result = jobj.getString("access_token");
}
ele = new Element("token_cache",result);
//两小时内有效
redisTemplate.opsForValue().set("token_cache", ele, 120,TimeUnit.MINUTES);
//tokenCache.put(ele);
}
return result;
}
/**
* 获取jsapi_ticket
* @param accessToken 获取jsapi_ticket需要填写access_token
* @return String jsapi_ticket
*/
public static String getJsapiTicket(String accessToken){
String url = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=" + accessToken + "&type=jsapi";
String ticketStr = HTTPSClient.sendGet(url);
JSONObject obj = JSONObject.fromObject(ticketStr) ;
// 获取jsapi_ticket
String ticket = (String) obj.get("ticket");
return ticket;
}
/**
* 发送文本消息接口
* @param access_token 凭证
* @param openId 目标用户
* @param text 文本
* @return json
*/
public static String sendGroupMessage_text(String access_token,String openId,String text){
// String url = "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token="+access_token;
// String url = "https://api.weixin.qq.com/cgi-bin/message/mass/sendall?access_token="+access_token;
String url="https://api.weixin.qq.com/cgi-bin/message/mass/send?access_token=63jVygxyIkK6oUCeM2YuzZHYLuzrkhSf6eDwmdd2HkXvIxnbfYIzQNMnt7deEWugUUobmyxNrZZa4gEMx1G0wtEJFqofT1sA3yvm9ZVctGPEG0B9DO0L8c3j3cnCC5XtZYRhAEATSL";
JSONObject obj = new JSONObject();
String openList=getOpenIdList(access_token);
JSONObject opnejson=JSONObject.fromObject(openList);
JSONObject opneIdsjson=(JSONObject) opnejson.get("data");
obj.put("touser", "o22lhwRZP2zbXff7UHH3J8oqH8A0");
obj.put("msgtype", "text");
Map map1=new HashMap();
map1.put("content","30+70");
obj.put("text",map1);
String result =HTTPSClient.sendPost(url, obj.toString());
return result;
}
/*
* 获取openId 列表
* */
public static String getOpenIdList(String access_token){
String url="https://api.weixin.qq.com/cgi-bin/user/get?access_token="+access_token;
String result=HTTPSClient.sendGet(url);
return result;
}
public Map<String,Object> getJspaiSign(String url) {
Map<String,Object> jsonObject = new HashMap<>();
// 时间戳
long timeStamp = System.currentTimeMillis();
// 随机字符串
String nonceStr = Integer.toString(((int) ((Math.random() + 1) * 1000000)));
// 凭证
String accessToken = getToken("client_credential",WxConfig.APPID,WxConfig.APPSECRET);
// 票据
String ticket = getJsapiTicket(accessToken);
String signature = "";
String params = "jsapi_ticket=" + ticket + "&noncestr=" + nonceStr + "&timestamp=" + timeStamp + "&url=" + url;
try {
// 获取签名
MessageDigest crypt = MessageDigest.getInstance("SHA-1");
crypt.reset();
crypt.update(params.getBytes("UTF-8"));
signature = byteToHex(crypt.digest());
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
jsonObject.put("timestamp", timeStamp);
jsonObject.put("nonceStr", nonceStr);
jsonObject.put("signature", signature);
return jsonObject;
}
public static String byteToHex(final byte[] hash) {
Formatter formatter = new Formatter();
for (byte b : hash) {
formatter.format("%02x", b);
}
String result = formatter.toString();
formatter.close();
return result;
}
/*@param title 消息标题
* @param description 消息描述
* @param url 点击链接跳转地址
* @param picurl 图片地址
* @return*/
/**
* 发送图文消息接口
* @param access_token
* @param openId
* @param news JSONArray 最多支持10条图文消息
* [
* {"title": "Happy Day","description": "Is Really A Happy Day","url": "URL","picurl": "PIC_URL"}
* ]
*
*/
public static String sendGroupMessage_news(String access_token,String openId,JSONArray news){
String url = "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token="+access_token;
JSONObject obj = new JSONObject();
obj.put("group", "网迅");
obj.put("msgtype", "news");
JSONObject newsObj = new JSONObject();
newsObj.put("articles", news);
obj.put("news", newsObj);
String result = HTTPSClient.sendPost(url, obj.toString());
return result;
}
/**
* 发送文本消息接口
* @param access_token 凭证
* @param openId 目标用户
* @param text 文本
* @return json
*/
public static String sendMessage_text(String access_token,String openId,String text){
String url = "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=63jVygxyIkK6oUCeM2YuzZHYLuzrkhSf6eDwmdd2HkXvIxnbfYIzQNMnt7deEWugUUobmyxNrZZa4gEMx1G0wtEJFqofT1sA3yvm9ZVctGPEG0B9DO0L8c3j3cnCC5XtZYRhAEATSL";
JSONObject obj = new JSONObject();
obj.put("touser", "o22lhwRZP2zbXff7UHH3J8oqH8A0");
obj.put("msgtype", "text");
JSONObject txtObj = new JSONObject();
txtObj.put("content", "30+70");
obj.put("text", txtObj);
String result = HTTPSClient.sendPosts(url, obj.toString());
return result;
}
/**
* 发送链接消息接口
* @param access_token 凭证
* @param openId 目标用户
* @param title 链接标题
* @param link_url 链接地址
* @return json
*/
public static String sendMessage_link(String access_token,String openId,String title,String link_url){
String url = "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token="+access_token;
JSONObject obj = new JSONObject();
obj.put("touser", openId);
obj.put("msgtype", "link");
JSONObject linkObj = new JSONObject();
linkObj.put("title", title);
linkObj.put("url", link_url);
obj.put("link", linkObj);
String result = HTTPSClient.sendPost(url, obj.toString());
return result;
}
/*@param title 消息标题
* @param description 消息描述
* @param url 点击链接跳转地址
* @param picurl 图片地址
* @return*/
/**
* 发送图文消息接口
* @param access_token
* @param openId
* @param news JSONArray 最多支持10条图文消息
* [
* {"title": "Happy Day","description": "Is Really A Happy Day","url": "URL","picurl": "PIC_URL"}
* ]
*
*/
public static String sendMessage_news(String access_token,String openId,JSONArray news){
String url = "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token="+access_token;
JSONObject obj = new JSONObject();
obj.put("touser", openId);
obj.put("msgtype", "news");
JSONObject newsObj = new JSONObject();
newsObj.put("articles", news);
obj.put("news", newsObj);
String result = HTTPSClient.sendPost(url, obj.toString());
return result;
}
public static String create_menu(String access_token,String openId,JSONArray news){
String url = "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token="+access_token;
JSONObject obj = new JSONObject();
obj.put("touser", openId);
obj.put("msgtype", "news");
JSONObject newsObj = new JSONObject();
newsObj.put("articles", news);
obj.put("news", newsObj);
String result = HTTPSClient.sendPost(url, obj.toString());
return result;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
* 获取文本消息XML
* @param toUser 接收方帐号(收到的OpenID)
* @param fromUser 公众号易信ID(参照“接收消息”中的ToUserName)
* @param createTime 消息创建时间 (整型)
* @param msgType text
* @param content 回复的消息内容(换行:在content中能够换行,易信客户端就支持换行显示)
* @return
*/
public static String return_text(String toUser,String fromUser,Integer createTime,String msgType,String content){
String xml =
"<xml>"
+"<ToUserName><![CDATA["+toUser+"]]></ToUserName>"
+"<FromUserName><![CDATA["+fromUser+"]]></FromUserName>"
+"<CreateTime>"+createTime+"</CreateTime>"
+"<MsgType><![CDATA["+msgType+"]]></MsgType>"
+"<Content><![CDATA["+content+"]]></Content>"
+"</xml>";
return xml;
}
/**
* 获取回复图文消息xml
* @param toUser 接收方帐号(收到的OpenID)
* @param fromUser 公众号易信ID(参照“接收消息”中的ToUserName)
* @param createTime 消息创建时间 (整型)
* @param msgType news
* @param items List<String[]> [0]:图文消息标题 [1]:图文消息描述 [2]:图片链接 [3]:点击图文消息跳转链接
* @return
*/
public static String return_picUrl(String toUser, String fromUser, Integer createTime, String msgType, List<String[]> items) {
StringBuffer sb = new StringBuffer();
sb.append("<xml>");
sb.append("<ToUserName><![CDATA[" + toUser + "]]></ToUserName>");
sb.append("<FromUserName><![CDATA[" + fromUser + "]]></FromUserName>");
sb.append("<CreateTime>" + createTime + "</CreateTime>");
sb.append("<MsgType><![CDATA[news]]></MsgType>");
sb.append("<ArticleCount>" + items.size() + "</ArticleCount>");
sb.append("<Articles>");
for(Object[] obj : items) {
sb.append("<item>");
sb.append("<Title><![CDATA[" + obj[0] + "]]></Title>");
sb.append("<Description><![CDATA[" + obj[1] + "]]></Description>");
sb.append("<PicUrl><![CDATA[" + obj[2] + "]]></PicUrl>");
sb.append("<Url><![CDATA[" + obj[3] + "]]></Url>");
sb.append("</item>");
}
sb.append("</Articles>");
sb.append("</xml>");
return sb.toString();
}
/**
* 终端登记图文页数组
* @param openId
* @return
*/
public static String[] zddj_page(String openId) {
/*String[] str = new String[]{"终端登记", "终端登记", "https://nos.163.com/yixinpublic/pr_8-jqipwwv8polh-seiahlw==_1423981193_6571103", "http://120.24.88.216/xyjl/yixinuser/the-sales-registration.jsp?openId=" + openId};
return str;*/
return commonPage("http://wenjun.pub/xyjl/yx/bind/sales-bind!toReg.action?openId=" + openId, "终端登记", "点击进入终端登记界面", "https://nos.163.com/yixinpublic/pr_8-jqipwwv8polh-seiahlw==_1423981193_6571103");
}
/**
* 店员销量TOP5榜单图文页数组
* @param openId
* @return
*/
public static String[] terTop_page(String openId){
String[] str = new String[]{"终端TOP榜","终端TOP榜","https://nos.163.com/yixinpublic/pr_mzw1uyt7l0sqiloodepj2g==_1437708277_48269407","http://120.24.88.216/xyjl/yx/report/mobile/mobile-report!toTerTopPage.action?openId="+openId};
return str;
}
/**
* TOP5bangdan图文页数组
* @param openId
* @return
*/
public static String[] top_page(String openId){
String[] str = new String[]{"奖励TOP榜","TOP5榜单","https://nos.163.com/yixinpublic/pr_9xmo9qrwhykzv03wwc9icq==_1435911065_45762356","http://120.24.88.216/xyjl/yx/report/mobile/mobile-report!toTopPage.action?openId="+openId};
return str;
}
/**
* 终端登记明细查询图文页数组
* @param openId
* @return
*/
public static String[] djmxcx_page(String openId){
String[] str = new String[]{"奖励查询","终端奖励明细查询","https://nos.163.com/yixinpublic/pr_6lpschhp5dhfxtbrcz288w==_1423981001_6569803","http://120.24.88.216/xyjl/yx/report/mobile/mobile-report!toFrontlineStaffSecondPage.action?openId="+openId};
return str;
}
/**
* 登记查询图文页数组
* @param openId
* @return
*/
public static String[] djcx_page(String openId){
String[] str = new String[]{"奖励查询","终端销售奖励查询","https://nos.163.com/yixinpublic/pr_r8oamwtnvnfblpuyffsbsw==_1425439255_10135230","http://120.24.88.216/xyjl/yx/report/mobile/mobile-report!toFrontlineStaffFirstPage.action?openId="+openId};
return str;
}
/**
* 投诉建议进度查询
* @param openId
* @return
*/
public static String[] tsjy_page(String openId) {
/*String[] str = new String[]{"进度查询","进度查询","https://nos.163.com/yixinpublic/pr_p71ybejuqqctefcsseli_w==_1423980900_6267434","http://120.24.88.216/xyjl/yx/appeal/appeal!toPage.action?openId="+openId};
return str;*/
return commonPage("http://wenjun.pub/xyjl/yx/appeal/appeal!toPage.action?openId=" + openId, "在线申诉", "在线申诉", "https://nos.163.com/yixinpublic/pr_p71ybejuqqctefcsseli_w==_1423980900_6267434");
}
/**
* 反馈/建议
* @param openId
* @return
*/
public static String[] ts_page(String openId){
/*String[] str = new String[]{"投诉建议","投诉进度查询","https://nos.163.com/yixinpublic/pr_p71ybejuqqctefcsseli_w==_1423980900_6267434","http://120.24.88.216/xyjl/yx/appeal/appeal!toAppealPage.action?openId="+openId};
return str;*/
return commonPage("http://wenjun.pub/xyjl/yx/appeal/appeal!toAppealPage.action?openId=" + openId, "在线申诉", "在线申诉", "https://nos.163.com/yixinpublic/pr_p71ybejuqqctefcsseli_w==_1423980900_6267434");
}
/**
* 手机绑定图文页数组
* @param openId
* @return
*/
public static String[] bdsj_page(String openId) {
/*String[] str = new String[]{"绑定手机", "绑定手机", "https://nos.163.com/yixinpublic/pr_9egota4nyl_dmoducr7csq==_1423980707_6568520", "http://120.24.88.216/xyjl/yixinuser/bind.jsp?openId=" + openId};
return str;*/
return commonPage("http://wenjun.pub/xyjl/yx/bind/sales-bind!toBindPage.action?openId=" + openId, "绑定手机", "营业员手机号与易信号绑定", "https://nos.163.com/yixinpublic/pr_6ketettmxd5-s-b0qjmqdq==_1424945149_8625212");
}
/**
* 用户个人信息界面
* @param openId
* @return
*/
public static String[] userInfoPage(String openId) {
return commonPage("http://wenjun.pub/xyjl/yx/system/sales!salesInfo.action?openId=" + openId, "个人信息", "营业员个人信息", "https://nos.163.com/yixinpublic/pr_6byhe_qrvu8cc85i8t3dcw==_1425288345_10376617");
}
public static String[] terminalAwardListPage(String openId) {
return commonPage("http://wenjun.pub/xyjl/yx/report/mobile/mobile-report!toTerList.action?openId=" + openId, "终端奖励", "终端的奖励信息查询", "https://nos.163.com/yixinpublic/pr_4pnt4kmgl002jqn3xyr34q==_1425439428_9798017");
}
/**
* 系统介绍页面
* @param openId
* @return
*/
public static String[] info_page(String openId) {
String url = "http://wenjun.pub/xyjl/info.jsp";
return commonPage(url, "一线销售终端登记及奖励系统", "", "https://nos.163.com/yixinpublic/pr_9egota4nyl_dmoducr7csq==_1423980707_6568520");
}
/**
* 通用的xml图文数组
* @param url
* @param title
* @param context
* @param pic
* @return
*/
public static String[] commonPage(String url, String title, String context, String pic) {
String[] str = new String[]{title, context, pic, url};
return str;
}
public static String sendMsg(String sendNumber,String msg){
String url = "http://120.24.88.216:8080/PearSmsCenter/SendValidateSms";
try {
url+="?sendNumber="+sendNumber;
url+="&msg="+URLEncoder.encode(URLEncoder.encode(msg,"utf-8"),"UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
String result="";
result = HTTPSClient.sendGet(url);
return result;
}
/**
* 通过code换取access_token
* @param code
* @return
*/
public static String getAccess_tokenByCode(String code){
String url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid="+WxConfig.APPID+"&secret="+WxConfig.APPSECRET+"&code="+code+"&grant_type=authorization_code";
String result="";
result = HTTPSClient.sendGet(url);
System.out.println(url);
return result;
}
/**
* 刷新access_token
* @return
*/
public static String refresh_token(String refresh_token){
String url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid="+WxConfig.APPID+"&grant_type=refresh_token&refresh_token="+refresh_token;
// String url = "https://api.weixin.qq.com/sns/oauth2/refresh_token?appid=wxfc18f5186b729d15&grant_type=refresh_token&refresh_token="+refresh_token;
String result="";
result = HTTPSClient.sendPost(url,"");
return result;
}
/*public static void main(String[] args) {
// String url="https://api.weixin.qq.com/cgi-bin/token?grant_type="+grant_type+"&appid="+appid+"&secret="+secret;b
String token = WxInterfacesUtil.getToken("client_credential", "wx42f959d029fed0ea", "4d7a334db8f7a414f3665c18cbc187d8");
JSONObject obj = new JSONObject();
obj.put("title", "公告测试");
obj.put("description", "这是一条系统测试公告,请勿回复!");
obj.put("url", "http://120.24.88.216:7033/xyjl/info.jsp");
obj.put("picurl", "http://120.24.88.216:7033/xyjl/images/login/bg1.jpg");
JSONArray arr = new JSONArray();
arr.add(obj);
String str = WxInterfacesUtil.sendGroupMessage_news(token, null, arr);
System.out.println(str);
//WxInterfacesUtil.sendMsg("13542107342", "test");
System.out.println("token=="+token);
}
*/
/**
* 生成二维码
* @param type 1:临时二维码 2:永久二维码
* @param sceneType 1:整形场景值 2:字符串场景值
* @throws IOException
* @throws ParseException
*/
public static String createCode(int type, int sceneType, String scene, String token) throws ParseException, IOException{
String url = "";
if(type == 1){
url = WxConfig.TEMPORARY_CODE_URL ;
}
else{
url = WxConfig.PERMANENT_CODE_URL;
}
url += token;
String params = getSendStr(type, sceneType, scene);
// String respStr = HTTPSClient.sendPosts(url,params);
String respStr = HttpService.sendPost(url,params);
Map map = JSONObject.fromObject(respStr);
String ticket = (String)map.get("ticket");
String codeUrl = WxConfig.TICKET_CODE_URL + URLEncoder.encode(ticket,"UTF-8");
return codeUrl;
}
/**
* 网页授权获取用户信息
* @param code 用于获取openid和access_token
* 这个access_token与基础access_token不同,专门用与获取用户信息
* @throws UnsupportedEncodingException
*/
public static String getUserInfo(String code) throws UnsupportedEncodingException{
String url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid="+ WxConfig.APPID +"&secret="+ WxConfig.APPSECRET +"&code="+code+"&grant_type=authorization_code";
String result = HTTPSClient.sendGet(url);
JSONObject obj = JSONObject.fromObject(result);
String infoUrl = "https://api.weixin.qq.com/sns/userinfo?access_token="+ obj.get("access_token") +"&openid="+ obj.get("openid") +"&lang=zh_CN";
String userInfo = HTTPSClient.sendGet(infoUrl);
JSONObject userObj = JSONObject.fromObject(userInfo);
return userInfo.toString();
}
/**
* 网页授权根据open_id和特殊access_token获取用户信息
* 这个access_token与基础access_token不同,专门用与获取用户信息
* @throws UnsupportedEncodingException
*/
public static JSONObject getWxInfo(String open_id, String access_token) throws UnsupportedEncodingException{
String infoUrl = "https://api.weixin.qq.com/sns/userinfo?access_token="+ access_token +"&openid="+ open_id +"&lang=zh_CN";
String userInfo = HTTPSClient.sendGet(infoUrl);
// 解决微信发送的中文信息乱码
userInfo = new String(userInfo.getBytes("ISO-8859-1"), "UTF-8");
JSONObject userObj = JSONObject.fromObject(userInfo);
return userObj;
}
/**
* 获取凭证
* @return
*/
public static String getAccessToken(){
String result = HTTPSClient.sendGet(WxConfig.ACCESS_TOKEN_URL);
JSONObject json = JSONObject.fromObject(result);
return (String)json.get("access_token");
}
/**
* 获取生成二维码所需的post
* @param type 1:临时二维码 2:永久二维码
* @param sceneType 1:整形场景值 2:字符串场景值
*/
public static String getSendStr(int type,int sceneType,String scene){
String params = "";
if(type == 1 && sceneType == 1){
params = "{\"expire_seconds\":604800,\"action_name\":\"QR_SCENE\",\"action_info\":"
+ "{\"scene\":{\"scene_id\":"+ scene +"}}}";
}
else if(type == 2 && sceneType == 1){
params = "{\"action_name\":\"QR_LIMIT_STR_SCENE\",\"action_info\":"
+ "{\"scene\":{\"scene_str\":\""+ scene +"\"}}}";
}
else if(type == 2 && sceneType ==2){
params = "{\"action_name\":\"QR_LIMIT_STR_SCENE\",\"action_info\":"
+ "{\"scene\":{\"scene_str\":\""+ scene +"\"}}}";
}
return params;
}
/**
* 发送审核结果通知
* @return
*/
public static String sendAppealResult(String access_token,String openid,String title,String appealResult,String replyContet,String detailUrl){
String url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + access_token;
String message = "{"
+"\"touser\": \""+openid+"\", "
+"\"template_id\": \"TJO_y05LF4-u8dyCMhnu3AsAplRxpFNrG_-plnCEdUA\", "
+"\"url\": \""+ detailUrl +"\", "
+"\"data\": {"
+"\"first\": {"
+"\"value\":\"您的申诉已处理完毕!\","
+"\"color\":\"#173177\""
+"}, "
+"\"keyword1\": {"
+"\"value\":\""+ title +"\","
+"\"color\":\"#173177\""
+"}, "
+"\"keyword2\": {"
+"\"value\":\""+ appealResult +"\","
+"\"color\":\"#173177\""
+"}, "
+"\"remark\": {"
+"\"value\":\""+ replyContet +"\","
+"\"color\":\"#173177\""
+"}"
+"}"
+"}";
String result = HTTPSClient.sendPosts(url, message);
return result;
}
/**
* 发送业务办理邀请的模板信息
* @return
*/
public static String sendBusinessTransactionInvitation(String access_token,String openid,String salemanName,String clickUrl){
SimpleDateFormat sf = new SimpleDateFormat("yyyy年MM月dd日 HH时mm分ss秒");
String date = sf.format(new Date());
String url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + access_token;
String message = "{"
+"\"touser\": \""+openid+"\", "
+"\"template_id\": \"QUJQiH14xgHa98zonF1s9oNu7_xXLsJHIh9n0cJN67Q\", "
+"\"url\": \""+ clickUrl +"\", "
+"\"data\": {"
+"\"first\": {"
+"\"value\":\"尊敬的客户,你正在向业务办理人员"+ salemanName +"发起业务办理!\","
+"\"color\":\"#173177\""
+"}, "
+"\"keyword1\": {"
+"\"value\":\""+ date +"\","
+"\"color\":\"#173177\""
+"}, "
+"\"keyword2\": {"
+"\"value\":\"线下销售\","
+"\"color\":\"#173177\""
+"}, "
+"\"keyword3\": {"
+"\"value\":\""+ salemanName +"\","
+"\"color\":\"#173177\""
+"}, "
+"\"remark\": {"
+"\"value\":\"请点击进行业务办理!\","
+"\"color\":\"#173177\""
+"}"
+"}"
+"}";
String result = HTTPSClient.sendPosts(url, message);
return result;
}
/**
* 发送解绑通知
* @return
*/
public static String sendUnbindInfo(String access_token,String openid,String account){
String url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + access_token;
String message = "{"
+"\"touser\": \""+openid+"\", "
+"\"template_id\": \"12Q_7dxz4GHA2UTJo_2PHZNhprPmTQPKKEiNjErNNJI\", "
+"\"url\": \"\", "
+"\"data\": {"
+"\"first\": {"
+"\"value\":\"您好,你的微信与飞Young系统的账号解除绑定!\","
+"\"color\":\"#173177\""
+"}, "
+"\"keyword1\": {"
+"\"value\":\""+ account +"\","
+"\"color\":\"#173177\""
+"}, "
+"\"keyword2\": {"
+"\"value\":\"解绑后,你的微信进入飞Young合伙人公众号菜单需要登录\","
+"\"color\":\"#173177\""
+"}, "
+"\"remark\": {"
+"\"value\":\"如该解绑动作不是本人操作,请通知管理员!\","
+"\"color\":\"#173177\""
+"}"
+"}"
+"}";
String result = HTTPSClient.sendPosts(url, message);
System.out.println(result);
return result;
}
/**
* 发送佣金结算通知
* @return
*/
public static String sendBonusInfo(String access_token,String openid,String account){
String url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + access_token;
String message = "{"
+"\"touser\": \""+openid+"\", "
+"\"template_id\": \"12Q_7dxz4GHA2UTJo_2PHZNhprPmTQPKKEiNjErNNJI\", "
+"\"url\": \"\", "
+"\"data\": {"
+"\"first\": {"
+"\"value\":\"您好,你的微信与飞Young系统的账号解除绑定!\","
+"\"color\":\"#173177\""
+"}, "
+"\"keyword1\": {"
+"\"value\":\""+ account +"\","
+"\"color\":\"#173177\""
+"}, "
+"\"keyword2\": {"
+"\"value\":\"解绑后,你的微信进入飞Young合伙人公众号菜单需要登录\","
+"\"color\":\"#173177\""
+"}, "
+"\"remark\": {"
+"\"value\":\"如该解绑动作不是本人操作,请通知管理员!\","
+"\"color\":\"#173177\""
+"}"
+"}"
+"}";
String result = HTTPSClient.sendPosts(url, message);
System.out.println(result);
return result;
}
/**
* 发送申诉结果通知
* @return
*/
public static String sendAppealNotice(String access_token,String openid,String content, String time, String auditResult){
String url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + access_token;
String message = "{"
+"\"touser\": \""+openid+"\", "
+"\"template_id\": \"TJO_y05LF4-u8dyCMhnu3AsAplRxpFNrG_-plnCEdUA\", "
+"\"url\": \"\", "
+"\"data\": {"
+"\"first\": {"
+"\"value\":\"您好,您在"+ time +"提交的申请已经审核了!\","
+"\"color\":\"#173177\""
+"}, "
+"\"keyword1\": {"
+"\"value\":\""+ content +"\","
+"\"color\":\"#173177\""
+"}, "
+"\"keyword2\": {"
+"\"value\":\""+ auditResult +"\","
+"\"color\":\"#173177\""
+"}, "
+"\"remark\": {"
+"\"value\":\"\","
+"\"color\":\"#173177\""
+"}"
+"}"
+"}";
String result = HTTPSClient.sendPosts(url, message);
System.out.println(result);
return result;
}
/**
* 发货通知
* @return
*/
public static String sendDeliveryNotice(Map<String, String> map){
String url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + map.get("accessToken");
String message = "{"
+"\"touser\": \""+map.get("openId")+"\", "
+"\"template_id\": \"Z_DhP04JVUUFbGJfqvVb7q15xGXT9rXIl9RwPxAyjg0\", "
+"\"url\": \"\", "
+"\"data\": {"
+"\"first\": {"
+"\"value\":\""+ map.get("first") +"\","
+"\"color\":\"#173177\""
+"}, "
+"\"keyword1\": {"
+"\"value\":\""+ map.get("keyword1") +"\","
+"\"color\":\"#173177\""
+"}, "
+"\"keyword2\": {"
+"\"value\":\""+ map.get("keyword2") +"\","
+"\"color\":\"#173177\""
+"}, "
+"\"keyword3\": {"
+"\"value\":\""+ map.get("keyword3") +"\","
+"\"color\":\"#173177\""
+"}, "
+"\"keyword4\": {"
+"\"value\":\""+ map.get("keyword4") +"\","
+"\"color\":\"#173177\""
+"}, "
+"\"keyword5\": {"
+"\"value\":\""+ map.get("keyword5") +"\","
+"\"color\":\"#173177\""
+"}, "
+"\"remark\": {"
+"\"value\":\""+ map.get("remark") +"\","
+"\"color\":\"#173177\""
+"}"
+"}"
+"}";
String result = HTTPSClient.sendPosts(url, message);
System.out.println(result);
return result;
}
/**
* 下单通知
* @return
*/
public static String sendOrderNotice(Map<String, String> map){
String url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + map.get("accessToken");
String message = "{"
+"\"touser\": \""+map.get("openId")+"\", "
+"\"template_id\": \"kL1_WJAh2qLyjc8c1AD92uevEe3DLGX3MtCna6dWuL0\", "
+"\"url\": \"\", "
+"\"data\": {"
+"\"first\": {"
+"\"value\":\""+ map.get("first") +"\","
+"\"color\":\"#173177\""
+"}, "
+"\"keyword1\": {"
+"\"value\":\""+ map.get("keyword1") +"\","
+"\"color\":\"#173177\""
+"}, "
+"\"keyword2\": {"
+"\"value\":\""+ map.get("keyword2") +"\","
+"\"color\":\"#173177\""
+"}, "
+"\"keyword3\": {"
+"\"value\":\""+ map.get("keyword3") +"\","
+"\"color\":\"#173177\""
+"}, "
+"\"keyword4\": {"
+"\"value\":\""+ map.get("keyword4") +"\","
+"\"color\":\"#173177\""
+"}, "
+"\"keyword5\": {"
+"\"value\":\""+ map.get("keyword5") +"\","
+"\"color\":\"#173177\""
+"}, "
+"\"remark\": {"
+"\"value\":\"\","
+"\"color\":\"#173177\""
+"}"
+"}"
+"}";
String result = HTTPSClient.sendPosts(url, message);
return result;
}
/**
* 库存不足通知
* @return
*/
public static String sendRepertoryNotice(String access_token,String openid,String content, String time, String auditResult){
String url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + access_token;
String message = "{"
+"\"touser\": \""+openid+"\", "
+"\"template_id\": \"TJO_y05LF4-u8dyCMhnu3AsAplRxpFNrG_-plnCEdUA\", "
+"\"url\": \"\", "
+"\"data\": {"
+"\"first\": {"
+"\"value\":\"您好,您在"+ time +"提交的申请已经审核了!\","
+"\"color\":\"#173177\""
+"}, "
+"\"keyword1\": {"
+"\"value\":\""+ content +"\","
+"\"color\":\"#173177\""
+"}, "
+"\"keyword2\": {"
+"\"value\":\""+ auditResult +"\","
+"\"color\":\"#173177\""
+"}, "
+"\"remark\": {"
+"\"value\":\"\","
+"\"color\":\"#173177\""
+"}"
+"}"
+"}";
String result = HTTPSClient.sendPosts(url, message);
System.out.println(result);
return result;
}
/**
* 发送充值结果通知
* @return
*/
public static String sendRechargeNotice(Map<String, String> map){
String url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + map.get("accessToken");
String message = "{"
+"\"touser\": \""+map.get("openId")+"\", "
+"\"template_id\": \"8PqU7n7yM-yDXOMYFIMoacagEDLofQvxhOMB3NEQs8Y\", "
+"\"url\": \""+map.get("url")+"\", "
+"\"data\": {"
+"\"first\": {"
+"\"value\":\""+ map.get("first") +"\","
+"\"color\":\"#173177\""
+"}, "
+"\"keyword1\": {"
+"\"value\":\""+ map.get("keyword1") +"\","
+"\"color\":\"#173177\""
+"}, "
+"\"keyword2\": {"
+"\"value\":\""+ map.get("keyword2") +"\","
+"\"color\":\"#173177\""
+"}, "
+"\"keyword3\": {"
+"\"value\":\""+ map.get("keyword3") +"\","
+"\"color\":\"#173177\""
+"}, "
/* +"\"keyword4\": {"
+"\"value\":\""+ map.get("keyword4") +"\","
+"\"color\":\"#173177\""
+"}, "
+"\"keyword5\": {"
+"\"value\":\""+ map.get("keyword5") +"\","
+"\"color\":\"#173177\""
+"}, "*/
+"\"remark\": {"
+"\"value\":\""+ map.get("remark") +"\","
+"\"color\":\"#173177\""
+"}"
+"}"
+"}";
String result = HTTPSClient.sendPosts(url, message);
return result;
}
/** @param grant_type 获取access_token填写client_credential
* @param appid 第三方用户唯一凭证
* @param secret 第三方用户唯一凭证密钥,既appsecret*/
/**
* 获取凭证
* @return json token:获取到的凭证 expires_in:凭证有效时间,单位:秒
*/
public static String getFyToken(){
String result = null;
String url="https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wx9e2de8b5f756a4a4&secret=1d8efde4496e92fa9cbcc95f9ca63d4d";
String res = HTTPSClient.sendGet(url);
JSONObject jobj = JSONObject.fromObject(res);
if(jobj.has("access_token")){
result = jobj.getString("access_token");
}
return result;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment