Authored by tanling

市场推广活动add

package com.yoho.activity.common.bo;
/**
* Created by yoho on 2016/6/17.
*/
public class TencentMktActivityBO {
private Integer id;
private String activityName;
private String h5Title;
private String activityNormalPic;
private String activityEndPic;
private String shareImgUrl;
private String shareTitle;
private String shareContent;
private String activityDesc;
private Integer beginTime;
private Integer endTime;
private String couponPic;
private String buttonLink;
private Integer createTime;
private Byte status;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getActivityName() {
return activityName;
}
public void setActivityName(String activityName) {
this.activityName = activityName == null ? null : activityName.trim();
}
public String getH5Title() {
return h5Title;
}
public void setH5Title(String h5Title) {
this.h5Title = h5Title == null ? null : h5Title.trim();
}
public String getActivityNormalPic() {
return activityNormalPic;
}
public void setActivityNormalPic(String activityNormalPic) {
this.activityNormalPic = activityNormalPic == null ? null : activityNormalPic.trim();
}
public String getActivityEndPic() {
return activityEndPic;
}
public void setActivityEndPic(String activityEndPic) {
this.activityEndPic = activityEndPic == null ? null : activityEndPic.trim();
}
public String getShareImgUrl() {
return shareImgUrl;
}
public void setShareImgUrl(String shareImgUrl) {
this.shareImgUrl = shareImgUrl == null ? null : shareImgUrl.trim();
}
public String getShareTitle() {
return shareTitle;
}
public void setShareTitle(String shareTitle) {
this.shareTitle = shareTitle == null ? null : shareTitle.trim();
}
public String getShareContent() {
return shareContent;
}
public void setShareContent(String shareContent) {
this.shareContent = shareContent == null ? null : shareContent.trim();
}
public String getActivityDesc() {
return activityDesc;
}
public void setActivityDesc(String activityDesc) {
this.activityDesc = activityDesc == null ? null : activityDesc.trim();
}
public Integer getBeginTime() {
return beginTime;
}
public void setBeginTime(Integer beginTime) {
this.beginTime = beginTime;
}
public Integer getEndTime() {
return endTime;
}
public void setEndTime(Integer endTime) {
this.endTime = endTime;
}
public String getCouponPic() {
return couponPic;
}
public void setCouponPic(String couponPic) {
this.couponPic = couponPic == null ? null : couponPic.trim();
}
public String getButtonLink() {
return buttonLink;
}
public void setButtonLink(String buttonLink) {
this.buttonLink = buttonLink == null ? null : buttonLink.trim();
}
public Integer getCreateTime() {
return createTime;
}
public void setCreateTime(Integer createTime) {
this.createTime = createTime;
}
public Byte getStatus() {
return status;
}
public void setStatus(Byte status) {
this.status = status;
}
}
... ...
package com.yoho.activity.common.bo;
/**
* Created by yoho on 2016/6/17.
*/
public class TencentMktBO extends TencentMktActivityBO{
private static final long serialVersionUID = 8541063617667341354L;
private int flag = 1;
private String returnMsg;
public String getReturnMsg() {
return returnMsg;
}
public void setReturnMsg(String returnMsg) {
this.returnMsg = returnMsg;
}
private String shareUrl;
public int getFlag() {
return flag;
}
public void setFlag(int flag) {
this.flag = flag;
}
public String getShareUrl() {
return shareUrl;
}
public void setShareUrl(String shareUrl) {
this.shareUrl = shareUrl;
}
}
... ...
package com.yoho.activity.common.convert;
import com.yoho.activity.common.bo.OrderShareBO;
import com.yoho.activity.common.bo.TencentMktActivityBO;
import com.yoho.activity.common.bo.TencentMktBO;
import com.yoho.coupon.dal.model.TencentMktActivity;
import org.springframework.beans.BeanUtils;
/**
* Created by yoho on 2016/6/17.
*/
public class TencentMktActivityConvert {
public static TencentMktActivityBO db2bo(TencentMktActivity db){
if (db == null) {
return null;
}
TencentMktActivityBO bo=new TencentMktActivityBO();
BeanUtils.copyProperties(db, bo);
return bo;
}
public static TencentMktBO bo2boResponse(TencentMktActivityBO db){
if (db == null) {
return null;
}
TencentMktBO bo=new TencentMktBO();
BeanUtils.copyProperties(db, bo);
return bo;
}
}
... ...
package com.yoho.activity.controller;
import com.alibaba.fastjson.JSONObject;
import com.yoho.activity.common.ApiResponse;
import com.yoho.activity.common.bo.OrderShareBO;
import com.yoho.activity.common.bo.TencentMktBO;
import com.yoho.activity.common.vo.UserShareHistoryVO;
import com.yoho.activity.service.ITencentMktService;
import com.yoho.error.exception.ServiceException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource;
/**
* Created by yoho on 2016/6/17.
*/
public class TencentMktController {
static Logger log = LoggerFactory.getLogger(TencentMktController.class);
@Resource
ITencentMktService tencentMktService;
/**
* 发送短信验证码<br>
* 如果用户是新用户,则发送验证码,<br>
* 如果是老用户,则提醒用户
* @param area
* @param mobile
* @return
* @throws Exception
*/
@RequestMapping("/sendSms")
@ResponseBody
public ApiResponse sendSms(String area, String mobile) throws ServiceException {
log.info("sendSms with area={}, mobile={}", area, mobile);
ApiResponse response = tencentMktService.sendSms(area, mobile);
log.info("sendSms with area={}, mobile={}, response={}", area, mobile, response);
return response;
}
/**
* 查询该订单是否可以分享
*
* @return flag=0 参数异常,
* flag=2表示不存在分享活动,
* flag=3表示分享活动已结束,
* flag=4表示分享活动未开始,
* flag=1正常
*/
@RequestMapping(params = "/getActivityInfo")
@ResponseBody
public ApiResponse getActivityInfo(String activityCode) {
log.info("getActivityInfo param activityCode={}", activityCode);
TencentMktBO data = tencentMktService.getActivityInfo(activityCode);
log.info("getActivityInfo param activityCode={}", activityCode);
return new ApiResponse(data);
}
/**
* 验证验证码
* 该方法会执行后续一系列动作
* 1、验证验证码
* 2、判断该手机号码是否注册过有货账号,如果没有,则调用注册接口,注册。
* 4、调用接口发送优惠券
* 5、如果用户是新用户,则发送短信提醒用户。
* @param code
* @param area
* @param mobile
* @param client_id
* @return
* @throws ServiceException
*/
@RequestMapping("/validRegCodeAndSendCode")
@ResponseBody
public ApiResponse validRegCodeAndSendCode(String code, String area, String mobile, String client_id) throws ServiceException {
log.info("validRegCodeAndSendCode with code={},area={}, mobile={},", code, area, mobile);
ApiResponse response = tencentMktService.validCodeAndSendCode(code, area, mobile, client_id);
log.info("validRegCodeAndSendCode with code={}, area={}, mobile={}, response={}",code, area, mobile, response);
return response;
}
}
... ...
package com.yoho.coupon.dal;
import com.yoho.coupon.dal.model.TencentMktActivity;
public interface ITencentMktActivityDAO {
int deleteByPrimaryKey(Integer id);
int insert(TencentMktActivity record);
int insertSelective(TencentMktActivity record);
TencentMktActivity selectByPrimaryKey(Integer id);
TencentMktActivity selectByActivityCode(String activityCode);
int updateByPrimaryKeySelective(TencentMktActivity record);
int updateByPrimaryKey(TencentMktActivity record);
}
\ No newline at end of file
... ...
package com.yoho.coupon.dal.model;
public class TencentMktActivity {
private Integer id;
private String activityCode;
private String activityName;
private String h5Title;
private String activityNormalPic;
private String activityEndPic;
private String shareImgUrl;
private String shareTitle;
private String shareContent;
private String pcLink;
private String activityDesc;
private Integer beginTime;
private Integer endTime;
private String couponPic;
private String buttonLink;
private Integer createTime;
private Byte status;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getActivityCode() {
return activityCode;
}
public void setActivityCode(String activityCode) {
this.activityCode = activityCode == null ? null : activityCode.trim();
}
public String getActivityName() {
return activityName;
}
public void setActivityName(String activityName) {
this.activityName = activityName == null ? null : activityName.trim();
}
public String getH5Title() {
return h5Title;
}
public void setH5Title(String h5Title) {
this.h5Title = h5Title == null ? null : h5Title.trim();
}
public String getActivityNormalPic() {
return activityNormalPic;
}
public void setActivityNormalPic(String activityNormalPic) {
this.activityNormalPic = activityNormalPic == null ? null : activityNormalPic.trim();
}
public String getActivityEndPic() {
return activityEndPic;
}
public void setActivityEndPic(String activityEndPic) {
this.activityEndPic = activityEndPic == null ? null : activityEndPic.trim();
}
public String getShareImgUrl() {
return shareImgUrl;
}
public void setShareImgUrl(String shareImgUrl) {
this.shareImgUrl = shareImgUrl == null ? null : shareImgUrl.trim();
}
public String getShareTitle() {
return shareTitle;
}
public void setShareTitle(String shareTitle) {
this.shareTitle = shareTitle == null ? null : shareTitle.trim();
}
public String getShareContent() {
return shareContent;
}
public void setShareContent(String shareContent) {
this.shareContent = shareContent == null ? null : shareContent.trim();
}
public String getPcLink() {
return pcLink;
}
public void setPcLink(String pcLink) {
this.pcLink = pcLink == null ? null : pcLink.trim();
}
public String getActivityDesc() {
return activityDesc;
}
public void setActivityDesc(String activityDesc) {
this.activityDesc = activityDesc == null ? null : activityDesc.trim();
}
public Integer getBeginTime() {
return beginTime;
}
public void setBeginTime(Integer beginTime) {
this.beginTime = beginTime;
}
public Integer getEndTime() {
return endTime;
}
public void setEndTime(Integer endTime) {
this.endTime = endTime;
}
public String getCouponPic() {
return couponPic;
}
public void setCouponPic(String couponPic) {
this.couponPic = couponPic == null ? null : couponPic.trim();
}
public String getButtonLink() {
return buttonLink;
}
public void setButtonLink(String buttonLink) {
this.buttonLink = buttonLink == null ? null : buttonLink.trim();
}
public Integer getCreateTime() {
return createTime;
}
public void setCreateTime(Integer createTime) {
this.createTime = createTime;
}
public Byte getStatus() {
return status;
}
public void setStatus(Byte status) {
this.status = status;
}
}
\ No newline at end of file
... ...
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.yoho.coupon.dal.ITencentMktActivityDAO" >
<resultMap id="BaseResultMap" type="com.yoho.coupon.dal.model.TencentMktActivity" >
<id column="id" property="id" jdbcType="INTEGER" />
<result column="activity_code" property="activityCode" jdbcType="VARCHAR" />
<result column="activity_name" property="activityName" jdbcType="VARCHAR" />
<result column="h5_title" property="h5Title" jdbcType="VARCHAR" />
<result column="activity_normal_pic" property="activityNormalPic" jdbcType="VARCHAR" />
<result column="activity_end_pic" property="activityEndPic" jdbcType="VARCHAR" />
<result column="share_img_url" property="shareImgUrl" jdbcType="VARCHAR" />
<result column="share_title" property="shareTitle" jdbcType="VARCHAR" />
<result column="share_content" property="shareContent" jdbcType="VARCHAR" />
<result column="pc_link" property="pcLink" jdbcType="VARCHAR" />
<result column="activity_desc" property="activityDesc" jdbcType="VARCHAR" />
<result column="begin_time" property="beginTime" jdbcType="INTEGER" />
<result column="end_time" property="endTime" jdbcType="INTEGER" />
<result column="coupon_pic" property="couponPic" jdbcType="VARCHAR" />
<result column="button_link" property="buttonLink" jdbcType="VARCHAR" />
<result column="create_time" property="createTime" jdbcType="INTEGER" />
<result column="status" property="status" jdbcType="TINYINT" />
</resultMap>
<sql id="Base_Column_List" >
id, activity_code, activity_name, h5_title, activity_normal_pic, activity_end_pic,
share_img_url, share_title, share_content, pc_link, activity_desc, begin_time, end_time,
coupon_pic, button_link, create_time, status
</sql>
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
select
<include refid="Base_Column_List" />
from tencent_mkt_activity
where id = #{id,jdbcType=INTEGER}
</select>
<select id="selectByActivityCode" resultMap="BaseResultMap" parameterType="java.lang.String" >
select
<include refid="Base_Column_List" />
from tencent_mkt_activity
where activity_code = #{activityCode,jdbcType=VARCHAR}
AND status=1
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
delete from tencent_mkt_activity
where id = #{id,jdbcType=INTEGER}
</delete>
<insert id="insert" parameterType="com.yoho.coupon.dal.model.TencentMktActivity" >
insert into tencent_mkt_activity (id, activity_code, activity_name,
h5_title, activity_normal_pic, activity_end_pic,
share_img_url, share_title, share_content,
pc_link, activity_desc, begin_time,
end_time, coupon_pic, button_link,
create_time, status)
values (#{id,jdbcType=INTEGER}, #{activityCode,jdbcType=VARCHAR}, #{activityName,jdbcType=VARCHAR},
#{h5Title,jdbcType=VARCHAR}, #{activityNormalPic,jdbcType=VARCHAR}, #{activityEndPic,jdbcType=VARCHAR},
#{shareImgUrl,jdbcType=VARCHAR}, #{shareTitle,jdbcType=VARCHAR}, #{shareContent,jdbcType=VARCHAR},
#{pcLink,jdbcType=VARCHAR}, #{activityDesc,jdbcType=VARCHAR}, #{beginTime,jdbcType=INTEGER},
#{endTime,jdbcType=INTEGER}, #{couponPic,jdbcType=VARCHAR}, #{buttonLink,jdbcType=VARCHAR},
#{createTime,jdbcType=INTEGER}, #{status,jdbcType=TINYINT})
</insert>
<insert id="insertSelective" parameterType="com.yoho.coupon.dal.model.TencentMktActivity" >
insert into tencent_mkt_activity
<trim prefix="(" suffix=")" suffixOverrides="," >
<if test="id != null" >
id,
</if>
<if test="activityCode != null" >
activity_code,
</if>
<if test="activityName != null" >
activity_name,
</if>
<if test="h5Title != null" >
h5_title,
</if>
<if test="activityNormalPic != null" >
activity_normal_pic,
</if>
<if test="activityEndPic != null" >
activity_end_pic,
</if>
<if test="shareImgUrl != null" >
share_img_url,
</if>
<if test="shareTitle != null" >
share_title,
</if>
<if test="shareContent != null" >
share_content,
</if>
<if test="pcLink != null" >
pc_link,
</if>
<if test="activityDesc != null" >
activity_desc,
</if>
<if test="beginTime != null" >
begin_time,
</if>
<if test="endTime != null" >
end_time,
</if>
<if test="couponPic != null" >
coupon_pic,
</if>
<if test="buttonLink != null" >
button_link,
</if>
<if test="createTime != null" >
create_time,
</if>
<if test="status != null" >
status,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides="," >
<if test="id != null" >
#{id,jdbcType=INTEGER},
</if>
<if test="activityCode != null" >
#{activityCode,jdbcType=VARCHAR},
</if>
<if test="activityName != null" >
#{activityName,jdbcType=VARCHAR},
</if>
<if test="h5Title != null" >
#{h5Title,jdbcType=VARCHAR},
</if>
<if test="activityNormalPic != null" >
#{activityNormalPic,jdbcType=VARCHAR},
</if>
<if test="activityEndPic != null" >
#{activityEndPic,jdbcType=VARCHAR},
</if>
<if test="shareImgUrl != null" >
#{shareImgUrl,jdbcType=VARCHAR},
</if>
<if test="shareTitle != null" >
#{shareTitle,jdbcType=VARCHAR},
</if>
<if test="shareContent != null" >
#{shareContent,jdbcType=VARCHAR},
</if>
<if test="pcLink != null" >
#{pcLink,jdbcType=VARCHAR},
</if>
<if test="activityDesc != null" >
#{activityDesc,jdbcType=VARCHAR},
</if>
<if test="beginTime != null" >
#{beginTime,jdbcType=INTEGER},
</if>
<if test="endTime != null" >
#{endTime,jdbcType=INTEGER},
</if>
<if test="couponPic != null" >
#{couponPic,jdbcType=VARCHAR},
</if>
<if test="buttonLink != null" >
#{buttonLink,jdbcType=VARCHAR},
</if>
<if test="createTime != null" >
#{createTime,jdbcType=INTEGER},
</if>
<if test="status != null" >
#{status,jdbcType=TINYINT},
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.yoho.coupon.dal.model.TencentMktActivity" >
update tencent_mkt_activity
<set >
<if test="activityCode != null" >
activity_code = #{activityCode,jdbcType=VARCHAR},
</if>
<if test="activityName != null" >
activity_name = #{activityName,jdbcType=VARCHAR},
</if>
<if test="h5Title != null" >
h5_title = #{h5Title,jdbcType=VARCHAR},
</if>
<if test="activityNormalPic != null" >
activity_normal_pic = #{activityNormalPic,jdbcType=VARCHAR},
</if>
<if test="activityEndPic != null" >
activity_end_pic = #{activityEndPic,jdbcType=VARCHAR},
</if>
<if test="shareImgUrl != null" >
share_img_url = #{shareImgUrl,jdbcType=VARCHAR},
</if>
<if test="shareTitle != null" >
share_title = #{shareTitle,jdbcType=VARCHAR},
</if>
<if test="shareContent != null" >
share_content = #{shareContent,jdbcType=VARCHAR},
</if>
<if test="pcLink != null" >
pc_link = #{pcLink,jdbcType=VARCHAR},
</if>
<if test="activityDesc != null" >
activity_desc = #{activityDesc,jdbcType=VARCHAR},
</if>
<if test="beginTime != null" >
begin_time = #{beginTime,jdbcType=INTEGER},
</if>
<if test="endTime != null" >
end_time = #{endTime,jdbcType=INTEGER},
</if>
<if test="couponPic != null" >
coupon_pic = #{couponPic,jdbcType=VARCHAR},
</if>
<if test="buttonLink != null" >
button_link = #{buttonLink,jdbcType=VARCHAR},
</if>
<if test="createTime != null" >
create_time = #{createTime,jdbcType=INTEGER},
</if>
<if test="status != null" >
status = #{status,jdbcType=TINYINT},
</if>
</set>
where id = #{id,jdbcType=INTEGER}
</update>
<update id="updateByPrimaryKey" parameterType="com.yoho.coupon.dal.model.TencentMktActivity" >
update tencent_mkt_activity
set activity_code = #{activityCode,jdbcType=VARCHAR},
activity_name = #{activityName,jdbcType=VARCHAR},
h5_title = #{h5Title,jdbcType=VARCHAR},
activity_normal_pic = #{activityNormalPic,jdbcType=VARCHAR},
activity_end_pic = #{activityEndPic,jdbcType=VARCHAR},
share_img_url = #{shareImgUrl,jdbcType=VARCHAR},
share_title = #{shareTitle,jdbcType=VARCHAR},
share_content = #{shareContent,jdbcType=VARCHAR},
pc_link = #{pcLink,jdbcType=VARCHAR},
activity_desc = #{activityDesc,jdbcType=VARCHAR},
begin_time = #{beginTime,jdbcType=INTEGER},
end_time = #{endTime,jdbcType=INTEGER},
coupon_pic = #{couponPic,jdbcType=VARCHAR},
button_link = #{buttonLink,jdbcType=VARCHAR},
create_time = #{createTime,jdbcType=INTEGER},
status = #{status,jdbcType=TINYINT}
where id = #{id,jdbcType=INTEGER}
</update>
</mapper>
\ No newline at end of file
... ...
/**
*
*/
package com.yoho.activity.service;
import com.yoho.activity.common.ApiResponse;
import com.yoho.activity.common.bo.TencentMktBO;
import com.yoho.error.exception.ServiceException;
/**
* 描述:
*
* @author ping.huang
* 2016年4月1日
*/
public interface ITencentMktService {
/**
* 发送短信
* @param area
* @param mobile
* @return
* @throws Exception
*/
public ApiResponse sendSms(String area, String mobile) throws ServiceException;
/**
* 验证验证码
* 该方法会执行后续一系列动作
* 1、验证验证码
* 2、查询该手机号是否已经领取过该优惠券。如果已经领取,直接提示已经领取过;
* 3、如果未领取,则判断该手机号码是否注册过有货账号,如果没有,则调用注册接口,注册。
* 4、调用接口发送优惠券
* 5、如果用户是新用户,则发送短信提醒用户。
* @param code
* @param area
* @param mobile
* @param client_id
* @return
* @throws ServiceException
*/
public ApiResponse validCodeAndSendCode(String code, String area, String mobile, String client_id) throws ServiceException;
/**
* 查询活動
* @param activityCode
* @return
*/
public TencentMktBO getActivityInfo(String activityCode);
/**
* 注册
* @param area
* @param mobile
* @param client_type
* @return
* @throws ServiceException
*/
public ApiResponse register(String area, String mobile, String client_type) throws ServiceException;
/**
* 发送优惠券
*/
public ApiResponse sendCoupon(int uid) throws ServiceException;
/**
* 发送短信通知用户
*/
public void sendNoticeSms(String mobile, String password) throws ServiceException;
}
... ...
/**
*
*/
package com.yoho.activity.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.yoho.activity.common.ApiResponse;
import com.yoho.activity.common.bo.TencentMktActivityBO;
import com.yoho.activity.common.bo.TencentMktBO;
import com.yoho.activity.common.constatns.Constant;
import com.yoho.activity.common.convert.TencentMktActivityConvert;
import com.yoho.activity.common.helper.ClientSecretHelper;
import com.yoho.activity.common.redis.CacheKeyHelper;
import com.yoho.activity.common.utils.DateUtils;
import com.yoho.activity.common.utils.RandomUtil;
import com.yoho.activity.service.ITencentMktService;
import com.yoho.core.common.utils.AES;
import com.yoho.core.common.utils.MD5;
import com.yoho.core.redis.YHRedisTemplate;
import com.yoho.core.redis.YHValueOperations;
import com.yoho.core.rest.client.ServiceCaller;
import com.yoho.core.rest.client.hystrix.AsyncFuture;
import com.yoho.coupon.dal.ITencentMktActivityDAO;
import com.yoho.coupon.dal.model.TencentMktActivity;
import com.yoho.error.exception.ServiceException;
import com.yoho.service.model.promotion.request.ParamsConfigReq;
import com.yoho.service.model.promotion.response.EventConfigRsp;
import com.yoho.service.model.request.ProfileRequestBO;
import com.yoho.service.model.request.RegisterReqBO;
import com.yoho.service.model.response.ProfileInfoRsp;
import com.yoho.service.model.response.RegisterRspBO;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;
@Service
public class TencentMktServiceImpl implements ITencentMktService {
static Logger log = LoggerFactory.getLogger(TencentMktServiceImpl.class);
static Logger registerLog = LoggerFactory.getLogger("tencentRegestLog");
@Resource
ClientSecretHelper clientSecretHelper;
@Value("${gateway.url}")
private String gatewayUrl;
@Value("${sendSMS.password}")
private String sendSMSPassword;
@Resource
private ITencentMktActivityDAO tencentMktActivityDAO;
@Resource
private ServiceCaller service;
@Resource(name = "yhValueOperations")
private YHValueOperations<String, String> yhValueOperations;
@Resource(name = "yhRedisTemplate")
private YHRedisTemplate<String, String> yhRedisTemplate;
@Value("${tencentmkt.shareUrl}")
private String shareUrl;
public static final String TENCENT_MKT__ACTIVITY_CACHEKEY = "yh:activity:tencentmkt:activitykey";
@Override
public ApiResponse sendSms(String area, String mobile) throws ServiceException {
log.debug("sendSms with area={}, mobile={}", area, mobile);
// 检查参数
if (StringUtils.isEmpty(mobile)) {
log.warn("sendSms error mobile is empty with area={}, mobile={}", area, mobile);
return new ApiResponse(501, "手机号不能为空");
}
// 如果手机号中包含-符号,则说明是国际号
if (mobile.indexOf("-") > 0) {
String[] arr = mobile.split("-");
area = arr[0];
mobile = arr[1];
}
if (StringUtils.isEmpty(area)) {
area = "86";
}
// 验证新老用户
ProfileRequestBO bo = new ProfileRequestBO();
bo.setMobile(mobile);
bo.setArea(area);
bo.setCheckSSO(true);
ProfileInfoRsp result = service.call("users.getUserprofileByEmailOrMobile", bo, ProfileInfoRsp.class);
log.info("call users.getUserprofileByEmailOrMobile result is {}", result);
if(result != null && result.getUid() != 0){
log.warn("call getUserprofileByEmailOrMobile. user is exist. area={}, mobile={}", area, mobile);
return new ApiResponse(502, "该用户已经注册过了");
}
// 组装请求对象,并生成client_secret
Map<String, String> map = new HashMap<String, String>();
map.put("method", "app.passport.smsbind");
map.put("mobile", mobile);
map.put("area", area);
String param = clientSecretHelper.createClientSecret(map);
// 调用gateway的发送验证码请求
AsyncFuture<ApiResponse> response = service.get("sms.sendCode", gatewayUrl + "?" + param, null, ApiResponse.class, null);
return response.get();
}
@Override
public ApiResponse validCodeAndSendCode(String code, String area, String mobile, String client_id) throws ServiceException {
log.debug("validRegCodeAndSendCode with code={}, area={}, mobile={}", code, area, mobile);
// 验证验证码
ApiResponse response = validRegCode(code, area, mobile);
if (Constant.CODE_SUCCESS != response.getCode()) {
log.warn("validCodeAndSendCode error validCode is error with code={}, area={}, mobile={}", code, area, mobile);
response.setMessage("验证码错误");
return response;
}
// 判断用户是否已经注册过,如果未注册,则调用注册接口
// 老用户则直接返回
response = register(area, mobile, "web");
if (Constant.CODE_SUCCESS != response.getCode()) {
log.warn("validCodeAndSendCode error register error with code={}, area={}, mobile={}", code, area, mobile);
return response;
}
JSONObject registerJSON = (JSONObject) response.getData();
boolean newUser = registerJSON.getBooleanValue("newUser");
int uid = registerJSON.getIntValue("uid");
String password = registerJSON.getString("password");
//发送优惠券
response = sendCoupon(uid);
if (Constant.CODE_SUCCESS != response.getCode()) {
log.warn("validCodeAndSendCode error sendCoupon error with code={}, area={}, mobile={}", code, area, mobile);
return response;
}
//如果是新用户,则发送提醒短信
sendNoticeSms(mobile, password);
//调用成功,记录日志
JSONObject logJson = new JSONObject();
logJson.put("uid", uid);
logJson.put("client_id", client_id);
logJson.put("create_time", DateUtils.getcurrentDateTime());
logJson.put("mobile", mobile);
logJson.put("source", "tencentmkt");
logJson.put("ip", "");
logJson.put("collect_ip", "");
logJson.put("isnew", newUser ? "Y" : "N");
registerLog.info(logJson.toString());
return response;
}
private ApiResponse validRegCode(String regCode, String area, String mobile) throws ServiceException {
log.debug("validRegCode with regCode={}, area={}, mobile={}", regCode, area, mobile);
// 检查参数 :验证码
if (StringUtils.isEmpty(regCode)) {
log.warn("validRegCode with regCode={}, area={}, mobile={}", regCode, area, mobile);
return new ApiResponse(501, "验证码不能为空");
}
// 检查参数 :手机号码
if (StringUtils.isEmpty(mobile)) {
log.warn("validRegCode with regCode={}, area={}, mobile={}", regCode, area, mobile);
return new ApiResponse(501, "手机号码不能为空");
}
// 如果手机号中包含-符号,则说明是国际号
if (mobile.indexOf("-") > 0) {
String[] arr = mobile.split("-");
area = arr[0];
mobile = arr[1];
}
if (StringUtils.isEmpty(area)) {
area = "86";
}
// 组装请求对象,并生成client_secret
Map<String, String> map = new HashMap<String, String>();
map.put("method", "app.register.validRegCode");
map.put("code", regCode);
map.put("mobile", mobile);
map.put("area", area);
String param = clientSecretHelper.createClientSecret(map);
// 调用gateway的发送验证码请求
AsyncFuture<ApiResponse> response = service.get("sms.validRegCode", gatewayUrl + "?" + param, null, ApiResponse.class, null);
return response.get();
}
public TencentMktActivityBO getActivityInfoByCode(String activityCode) {
TencentMktActivityBO activityBO = CacheKeyHelper.string2Value(yhValueOperations.get(TENCENT_MKT__ACTIVITY_CACHEKEY), TencentMktActivityBO.class);
if(activityBO != null) {
log.info("obtain tencent mkt activity from cache, activityId: {}, activityName: {}", activityBO.getId(), activityBO.getActivityName());
return activityBO;
}
//缓存不命中,从数据库获取
TencentMktActivity db = tencentMktActivityDAO.selectByActivityCode(activityCode);
if (db == null) {
log.error("no tencent mkt activity exists");
return null;
}
activityBO = TencentMktActivityConvert.db2bo(db);
yhValueOperations.set(TENCENT_MKT__ACTIVITY_CACHEKEY, CacheKeyHelper.value2String(activityBO));
yhRedisTemplate.longExpire(TENCENT_MKT__ACTIVITY_CACHEKEY, 1, TimeUnit.MINUTES);
log.debug("tencent mkt activity, activityId: {}, activityName: {}", activityBO.getId(), activityBO.getActivityName());
return activityBO;
}
@Override
public TencentMktBO getActivityInfo(String activityCode) {
log.info("getActivityInfo params is activityCode={}", activityCode);
TencentMktBO bo = new TencentMktBO();
// 参数检查
if(StringUtils.isBlank(activityCode)){
log.warn("there is not activity,params is activityCode is null");
bo.setFlag(0);
bo.setReturnMsg("入力参数不对");
return bo;
}
// 1、查询此活动
TencentMktActivityBO activitydb = getActivityInfoByCode(activityCode);
if (activitydb == null) {
// 活动不存在
log.warn("there is not activity,params is activityCode={}", activityCode);
bo.setFlag(2);
bo.setReturnMsg("不存在该活动");
return bo;
}
bo.setH5Title(activitydb.getH5Title());
bo.setActivityEndPic(activitydb.getActivityEndPic());
// activityStatus:1-活动未开始 2-活动中 3-活动已结束 4-活动不存在
int nowtime = DateUtils.getCurrentTimeSecond();
if (activitydb.getEndTime() < nowtime) {
// 活动已结束
log.warn("activity is over ,params is activityCode={}", activityCode);
bo.setFlag(3);
bo.setReturnMsg("本次活动已经结束");
return bo;
}
if (activitydb.getBeginTime() > nowtime) {
// 活动未开始
log.warn("activity could not started ,params is activityCode={}",activityCode);
bo.setFlag(4);
bo.setReturnMsg("本次活动未开始");
return bo;
}
bo = TencentMktActivityConvert.bo2boResponse(activitydb);
bo.setFlag(1);
bo.setShareUrl(shareUrl);
log.info("getActivityInfo result is {}", bo);
return bo;
}
@Override
public ApiResponse register(String area, String mobile, String client_type) throws ServiceException {
log.debug("register with area={}, mobile={},client_type={}", area, mobile, client_type);
// 检查参数 :手机号码
if (StringUtils.isEmpty(mobile)) {
log.warn("register with area={}, mobile={}, client_type={}", area, mobile, client_type);
return new ApiResponse(501, "手机号码不能为空");
}
// 如果手机号中包含-符号,则说明是国际号
if (mobile.indexOf("-") > 0) {
String[] arr = mobile.split("-");
area = arr[0];
mobile = arr[1];
}
if (StringUtils.isEmpty(area)) {
area = "86";
}
// 1.根据手机号码查询,用户是否注册
ProfileRequestBO bo = new ProfileRequestBO();
bo.setMobile(mobile);
bo.setArea(area);
bo.setCheckSSO(true);
ProfileInfoRsp result = service.call("users.getUserprofileByEmailOrMobile", bo, ProfileInfoRsp.class);
log.info("call users.getUserprofileByEmailOrMobile result is {}", result);
// 查询用户不存在
JSONObject json = new JSONObject();
if (result == null || result.getUid() == 0) {
log.info("user not exists with mobile={}", mobile);
// 2.调用注册
RegisterReqBO registerReqBO = new RegisterReqBO();
registerReqBO.setArea(area);
registerReqBO.setProfile(mobile);
registerReqBO.setPassword(RandomUtil.getCharAndNumr(6, 2));
registerReqBO.setClient_type(client_type);
RegisterRspBO model = null;
try {
model = service.call("users.register", registerReqBO, RegisterRspBO.class);
log.info("call register new user.result is {}", model);
json.put("password", registerReqBO.getPassword());
// 3.记录新注册用户 领取人数
} catch (Exception e) {
log.warn("Redis exception. check get times. area is {}, mobile is {}, client_type={},exception is {}", area, mobile, client_type, e.getMessage());
return new ApiResponse(603, "领取优惠券失败");
}
json.put("uid", model.getUid());
}
// 3.已注册用户,则返回,提示该用户已经注册过了
else {
log.warn("call getUserprofileByEmailOrMobile. result={}", result);
return new ApiResponse(502, "该用户已经注册过了");
}
return new ApiResponse(json);
}
@Override
public ApiResponse sendCoupon(int uid) throws ServiceException {
log.info("sendCoupon with uid={}", uid);
EventConfigRsp eventConfigRsp = null;
try {
ParamsConfigReq paramsConfigReq = new ParamsConfigReq();
paramsConfigReq.setUid(Integer.valueOf(uid));
// TODO
paramsConfigReq.setEventCode("SEND_COCACOLA_COUPON");
paramsConfigReq.setClientType("web");
eventConfigRsp = service.call("promotion.sendCouponByConfig", paramsConfigReq, EventConfigRsp.class);
} catch (Exception e) {
log.error("sendCoupon error with uid={}", uid, e);
return new ApiResponse(601, "对不起,您不符合领取条件!请查看活动说明。");
}
if (eventConfigRsp == null || eventConfigRsp.getFlag() != 1) {
log.warn("sendCoupon error with uid={}", uid);
return new ApiResponse(602, "对不起,您不符合领取条件!请查看活动说明。");
}
log.info("sendCoupon success result is {}", eventConfigRsp);
return new ApiResponse(200, "优惠券领取成功");
}
@Override
public void sendNoticeSms(String mobile, String password) throws ServiceException {
log.info("sendNoticeSms with mobile={}", mobile);
String url = "http://www.ztsms.cn/sendSms.do?";
// TODO
String content = "【Yoho!Buy有货】恭喜您获得千元礼包,您的登录账户是"+ mobile +", 密码是"+ password +"(随机6\n" +
"位数字+2位字母);下载Yoho!Buy有货手机端http:"+"(最新地址),更多惊喜等着您!";
try {
String pwd = AES.decrypt("yoho96461qaz2wsx", this.sendSMSPassword);
url += "username=youhuo&password=" + MD5.md5(pwd) + "&mobile=" + mobile + "&content="+ content +"&productid=333333";
} catch (Exception e) {
log.error("AES.decrypt error with code={}", this.sendSMSPassword, e);
return;
}
// 调用接口发送短信请求
AsyncFuture<String> response = service.get("sms.sendSMS", url, null, String.class, null);
String result = response.get();
log.info("sendNoticeSms result is {}, mobile is {}", result, mobile);
}
}
... ...
... ... @@ -57,4 +57,6 @@ cocacola.wechat.share.url=http://testservice.yoho.cn/activity/cocacola/html/inde
orderShare.maxNum=3
orderShare.recevied.maxNum=5
orderShare.shareUrl=http://m.yohobuy.com/coupon/index
\ No newline at end of file
orderShare.shareUrl=http://m.yohobuy.com/coupon/index
tencentmkt.shareUrl=http://m.yohobuy.com/coupon/index
\ No newline at end of file
... ...
... ... @@ -117,6 +117,21 @@
<pattern>%msg%n</pattern>
</encoder>
</appender>
<!-- 可口可乐活动,注册日志-->
<appender name="TENCENT_REGEST_LOG" class="ch.qos.logback.core.rolling.RollingFileAppender">
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${catalina.home}/logs/%d{yyyy-MM-dd}/tencent_regest.log</fileNamePattern>
<!-- 日志最大的保存天数 -->
<maxHistory>${maxHistory}</maxHistory>
</rollingPolicy>
<triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
<maxFileSize>${maxFileSize}</maxFileSize>
</triggeringPolicy>
<encoder>
<pattern>%msg%n</pattern>
</encoder>
</appender>
<!-- 发送优惠券类型活动,注册日志-->
<appender name="COUPON_REGEST_LOG" class="ch.qos.logback.core.rolling.RollingFileAppender">
... ... @@ -192,5 +207,10 @@
<level value="INFO"/>
<appender-ref ref="COUPON_REGEST_LOG"/>
</logger>
<!--市场活动推广注册日志-->
<logger name="tencentRegestLog" additivity="true">
<level value="INFO"/>
<appender-ref ref="TENCENT_REGEST_LOG"/>
</logger>
</configuration>
\ No newline at end of file
... ...