trick9191 6 yıl önce
ebeveyn
işleme
a49ea8041e

+ 4 - 0
common/common-request-mapping/src/main/java/com/yihu/jw/rm/base/WechatRequestMapping.java

@ -18,6 +18,10 @@ public class WechatRequestMapping {
    }
    public static  class  WxQrcode{
        public static final String api_get="/getQrcode";
    }
    //微信按钮模块常量
    public static class WxMenu{
        public static final String api_create="/menu";

+ 1 - 1
server/svr-authentication/src/main/java/com/yihu/jw/security/core/userdetails/jdbc/WlyyUserDetailsService.java

@ -172,7 +172,7 @@ public class WlyyUserDetailsService extends JdbcDaoSupport implements UserDetail
    }
    /**
     * 更新失败次数
     * 更新登录失败次数
     * @param username
     * @param loginFailureCount
     */

+ 6 - 0
svr/svr-base/pom.xml

@ -109,6 +109,12 @@
            <artifactId>elasticsearch-starter</artifactId>
            <version>2.0.0</version>
        </dependency>
        <!-- 文件服务器 -->
        <dependency>
            <groupId>com.yihu</groupId>
            <artifactId>fastdfs-starter</artifactId>
            <version>2.0.0</version>
        </dependency>
    </dependencies>

+ 38 - 0
svr/svr-base/src/main/java/com/yihu/jw/base/endpoint/wx/WeChatQrcodeController.java

@ -0,0 +1,38 @@
package com.yihu.jw.base.endpoint.wx;
import com.yihu.jw.base.service.wx.WeChatQrcodeService;
import com.yihu.jw.restmodel.web.Envelop;
import com.yihu.jw.restmodel.web.endpoint.EnvelopRestEndpoint;
import com.yihu.jw.rm.base.BaseRequestMapping;
import com.yihu.jw.rm.base.WechatRequestMapping;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
/**
 * Created by Trick on 2018/9/7.
 */
@RestController
@RequestMapping(BaseRequestMapping.WeChat.PREFIX)
@Api(value = "微信二维码", description = "微信二维码", tags = {"微信二维码服务 - 微信二维码"})
public class WeChatQrcodeController extends EnvelopRestEndpoint {
    @Autowired
    private WeChatQrcodeService weChatQrcodeService;
    @PostMapping(value = WechatRequestMapping.WxMenu.api_create, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "生成微信二维码", notes = "生成微信二维码")
    public Envelop getQrcode(@ApiParam(name = "wxId", value = "微信id")
                             @RequestParam(value = "wxId", required = true)String wxId,
                             @ApiParam(name = "scene", value = "场景值")
                             @RequestParam(value = "scene", required = true)String scene) throws Exception{
        return success(weChatQrcodeService.getQrcode(wxId,scene));
    }
}

+ 51 - 0
svr/svr-base/src/main/java/com/yihu/jw/base/service/wx/WeChatQrcodeService.java

@ -0,0 +1,51 @@
package com.yihu.jw.base.service.wx;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.yihu.fastdfs.FastDFSUtil;
import com.yihu.jw.util.wechat.wxhttp.HttpUtil;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
/**
 * 微信二维码
 * Created by Trick on 2018/9/7.
 */
@Service
public class WeChatQrcodeService {
    @Autowired
    private FastDFSUtil fastDFSHelper;
    @Autowired
    private WxAccessTokenService wxAccessTokenService;
    public String getQrcode(String wechatId,String scene) throws Exception{
        String token_url = "https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=" + wxAccessTokenService.getWxAccessTokenById(wechatId);
        String params = "{\"action_name\": \"QR_LIMIT_STR_SCENE\", \"action_info\": {\"scene\": {\"scene_str\": \"" + scene + "\"}}}";
        String result = HttpUtil.sendPost(token_url, params);
        if (!StringUtils.isEmpty(result)) {
            JSONObject json = new JSONObject(result);
            if (json.has("ticket")) {
                // 请求输入流
                InputStream inputStream = null;
                // 下载二维码图片
                URL urlGet = new URL("https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket="
                        + URLEncoder.encode(json.get("ticket").toString(), "UTF-8"));
                HttpURLConnection connection = (HttpURLConnection) urlGet.openConnection();
                connection.connect();
                inputStream = connection.getInputStream();
                ObjectNode objectNode = fastDFSHelper.upload(inputStream,"png","微信二维码");
                return objectNode.get("fileId").toString().replaceAll("\"", "");
            }
        }
        return null;
    }
}

+ 7 - 1
svr/svr-base/src/main/resources/application.yml

@ -65,6 +65,8 @@ es:
    servicePackLog: base_service_package_log
  type:
    servicePackLog: base_service_package_log
fastDFS:
  fastdfs_file_url: http://172.19.103.54:80/
---
spring:
@ -84,6 +86,8 @@ es:
    servicePackLog: base_service_package_log
  type:
    servicePackLog: base_service_package_log
fastDFS:
  fastdfs_file_url: http://172.19.103.54:80/
---
spring:
  profiles: jwprod
@ -100,4 +104,6 @@ es:
  index:
    servicePackLog: base_service_package_log
  type:
    servicePackLog: base_service_package_log
    servicePackLog: base_service_package_log
fastDFS:
  fastdfs_file_url: http://172.19.103.54:80/