沈斌
2018-05-04 fda5a7a696628c9d430c765920ffd976c9532ec5
运维app
2 files added
5 files modified
133 ■■■■■ changed files
lib/taobao-sdk-java-auto_1455552377940-20160607.jar patch | view | raw | blame | history
pom.xml 27 ●●●●● patch | view | raw | blame | history
src/main/java/com/moral/controller/MobileController.java 52 ●●●●● patch | view | raw | blame | history
src/main/java/com/moral/entity/OperateUser.java 4 ●●● patch | view | raw | blame | history
src/main/java/com/moral/service/OperateUserService.java 2 ●●●●● patch | view | raw | blame | history
src/main/java/com/moral/service/impl/OperateUserServiceImpl.java 5 ●●●●● patch | view | raw | blame | history
src/main/java/com/moral/util/MessageUtils.java 43 ●●●●● patch | view | raw | blame | history
lib/taobao-sdk-java-auto_1455552377940-20160607.jar
Binary files differ
pom.xml
@@ -177,6 +177,15 @@
            <artifactId>jjwt</artifactId>
            <version>0.9.0</version>
        </dependency>
        <!-- 阿里大于 -->
        <dependency>
            <groupId>com.taobao.api</groupId>
            <artifactId>taobao-sdk</artifactId>
            <version>1.0.0</version>
            <scope>system</scope>
            <systemPath>${project.basedir}/lib/taobao-sdk-java-auto_1455552377940-20160607.jar</systemPath>
        </dependency>
    </dependencies>
    <build>
@@ -204,6 +213,24 @@
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>3.1.0</version>
                <executions>
                    <execution>
                        <id>copy-dependencies</id>
                        <phase>compile</phase>
                        <goals>
                            <goal>copy-dependencies</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${project.build.directory}/${project.build.finalName}/WEB-INF/lib</outputDirectory>
                            <includeScope>system</includeScope>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>
src/main/java/com/moral/controller/MobileController.java
@@ -8,6 +8,9 @@
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import com.moral.util.MessageUtils;
import com.taobao.api.ApiException;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.*;
import com.moral.common.bean.AppData;
@@ -135,4 +138,53 @@
        List<Organization> organizations = organizationService.getOrganizationsByAreaName(parameters);
        return new AppData<List<Organization>>(organizations);
    }
    /**
     * Send SMS
     *
     * @param mobile
     * @return
     */
    @PostMapping("sendSms")
    public AppData<String> sendSms(String mobile) {
        AppData apiData = new AppData();
        if (StringUtils.isBlank(mobile)){
            apiData.setErrno(1);
            apiData.setMessage("没有输入手机号码");
            apiData.setData("{}");
            return  apiData;
        }
        OperateUser user = operateUserService.getOperateUserByMobile(mobile);
        if (user==null){
            apiData.setErrno(1);
            apiData.setMessage("手机号没有关联用户");
            apiData.setData("{}");
            return  apiData;
        }
        //生成验证码
        String code = String.valueOf((Math.random() * 9 + 1) * 100000);
        user.setCode(code);
        operateUserService.updateOperateUserCode(user);
        //发送到手机
        try {
            int state = MessageUtils.sendMsg(mobile, code);
            if(state==0){
                apiData.setErrno(0);
                apiData.setMessage("发送验证码成功");
                apiData.setData("{}");
                return  apiData;
            }
            if(state==1){
                apiData.setErrno(1);
                apiData.setMessage("发送验证码失败");
                apiData.setData("{}");
                return  apiData;
            }
        } catch (ApiException e) {
            e.printStackTrace();
        }
        return new AppData<String>("");
    }
}
src/main/java/com/moral/entity/OperateUser.java
@@ -30,7 +30,9 @@
    private Date createTime;
    private Date expireTime;
    private String code;
    public Integer getUid() {
        return id;
    }
src/main/java/com/moral/service/OperateUserService.java
@@ -25,4 +25,6 @@
    Integer deleteOperateUsersByLogic(List<Integer> ids);
    PageBean queryByPageBean(PageBean pageBean);
    Integer updateOperateUserCode(OperateUser operateUser);
}
src/main/java/com/moral/service/impl/OperateUserServiceImpl.java
@@ -130,4 +130,9 @@
    public PageBean queryByPageBean(PageBean pageBean) {
        return MyBatisBaseMapUtil.queryPage(operateUserMapper,pageBean,ENTITY_CLASS);
    }
    @Override
    public Integer updateOperateUserCode(OperateUser operateUser) {
        return operateUserMapper.updateByPrimaryKeySelective(operateUser);
    }
}
src/main/java/com/moral/util/MessageUtils.java
New file
@@ -0,0 +1,43 @@
package com.moral.util;
import com.taobao.api.ApiException;
import com.taobao.api.DefaultTaobaoClient;
import com.taobao.api.TaobaoClient;
import com.taobao.api.domain.BizResult;
import com.taobao.api.request.AlibabaAliqinFcSmsNumSendRequest;
import com.taobao.api.response.AlibabaAliqinFcSmsNumSendResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class MessageUtils {
    private static Logger logger = LoggerFactory.getLogger(MessageUtils.class);
    public static int sendMsg(String mobile,String code) throws ApiException {
        String url = "http://gw.api.taobao.com/router/rest";
        String appkey = "23531128";
        String secret = "b079269785183c5a7520da9b8047bb42";
        TaobaoClient client = new DefaultTaobaoClient(url, appkey, secret);
        AlibabaAliqinFcSmsNumSendRequest req = new AlibabaAliqinFcSmsNumSendRequest();
        req.setExtend("");
        req.setSmsType("normal");
        req.setSmsFreeSignName("七星博士");
        //${address}发生警报,警报等级:${level},请马上处理。
        //req.setSmsParamString("{address:'" + "addre" + "',level:'" + 2 + "'}");
        req.setSmsParamString("{code:'" + code + "'}");
        req.setRecNum(mobile);
        req.setSmsTemplateCode("SMS_25781236");
        AlibabaAliqinFcSmsNumSendResponse rsp = client.execute(req);
        BizResult result = rsp.getResult();
        if (result == null) {
            logger.warn("短信报警通知失败" + rsp.getBody());
            return 1;
        }
        Boolean success = result.getSuccess();
        if (!success) {
            logger.warn("短信通知失败" + rsp.getBody());
            return 1;
        }
        return 0;
    }
}