Browse Source

调整二维码图片

Althars123 3 years ago
parent
commit
eb7201d9ad

+ 10 - 238
twzd-admin/src/test/java/com/miaxis/test/NormalTest.java

@@ -1,23 +1,15 @@
 package com.miaxis.test;
 
-import com.github.wxpay.sdk.WXPay;
-import com.github.wxpay.sdk.WXPayConfig;
-import com.github.wxpay.sdk.WXPayConstants;
-import com.github.wxpay.sdk.WXPayUtil;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.miaxis.TwzdApplication;
-import com.miaxis.common.config.WxPayConfigImpl;
-import com.miaxis.common.config.WxpayConfig;
-import com.miaxis.common.utils.XmlUtil;
 import com.miaxis.extension.service.IWxExtensionIncomeService;
-import com.miaxis.question.mapper.QuestionInfoMapper;
-import com.miaxis.question.vo.QuestionInfoExcelTypeVo;
-import com.miaxis.question.vo.QuestionInfoExcelVo;
 import com.miaxis.system.service.ISysUserService;
 import com.miaxis.user.service.IUserInfoService;
+import com.miaxis.wx.domain.WxForeverCode;
+import com.miaxis.wx.service.IWxForeverCodeService;
+import com.miaxis.wx.service.IWxMessageEvenService;
 import com.miaxis.wx.service.IWxTicketService;
 import com.miaxis.wx.service.impl.WxGzhServiceImpl;
-import org.apache.commons.lang3.RandomStringUtils;
-import org.apache.poi.hssf.usermodel.*;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -27,13 +19,6 @@ import org.springframework.test.context.ActiveProfiles;
 import org.springframework.test.context.junit4.SpringRunner;
 
 import javax.annotation.Resource;
-import java.io.FileOutputStream;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.util.List;
-import java.util.Map;
-import java.util.TreeMap;
 
 @ActiveProfiles("prodtest")
 @SpringBootTest(classes = TwzdApplication.class)
@@ -44,12 +29,6 @@ public class NormalTest {
     @Resource
     WxGzhServiceImpl wxGzhService;
 
-    @Resource
-    QuestionInfoMapper questionInfoMapper;
-
-    @Autowired
-    private WxpayConfig wxpayConfig;
-
     @Autowired
     IWxExtensionIncomeService wxExtensionIncomeService;
     @Autowired
@@ -61,9 +40,11 @@ public class NormalTest {
     @Autowired
     IWxTicketService wxTicketService;
 
+    @Autowired
+    IWxMessageEvenService iWxMessageEvenService;
 
-
-
+    @Autowired
+    IWxForeverCodeService wxForeverCodeService;
 
     @Value("${app.appid}")
     private String appid;
@@ -72,225 +53,16 @@ public class NormalTest {
     private String secret;
     @Test
     public void test666() throws Exception {
-
-        wxTicketService.transactionTest();
-    }
-
-
-    @Test
-    public void getGzhToken() throws Exception {
-        Map<String, String> sortMap = new TreeMap<String, String>();
-        sortMap.put("mch_id",wxpayConfig.getMerchantId());
-        sortMap.put("nonce_str", RandomStringUtils.randomAlphanumeric(32));
-        sortMap.put("sign_type","MD5");
-
-
-        WXPayConfig config = new WxPayConfigImpl();
-        String sign = WXPayUtil.generateSignature(sortMap, config.getKey(), WXPayConstants.SignType.MD5);
-        sortMap.put("sign", sign);
-        WXPay pay = new WXPay(config);
-
-        String url = "https://fraud.mch.weixin.qq.com/risk/getpublickey";
-        Map<String, String> resMap;
-        String xmlStr = pay.requestWithCert(url, sortMap, config.getHttpConnectTimeoutMs(), config.getHttpReadTimeoutMs());
-        System.out.println(xmlStr);
-        resMap = XmlUtil.xmlToMap(xmlStr);
-        String publicStr = resMap.get("pub_key");
-        System.out.println(publicStr);
-        //保存到本地
-//        File file = new File("E:\\public.pem");
-//        if (!file.exists()){
-//            file.mkdir();
-//        }
-        FileWriter fwriter = null;
-        try {
-            // true表示不覆盖原来的内容,而是加到文件的后面。若要覆盖原来的内容,直接省略这个参数就好
-            fwriter = new FileWriter("E:\\public.pem", false);
-            fwriter.write(publicStr);
-        } catch (IOException ex) {
-            ex.printStackTrace();
-        } finally {
-            try {
-                fwriter.flush();
-                fwriter.close();
-            } catch (IOException ex) {
-                ex.printStackTrace();
-            }
-        }
-    }
-
-
-
-
-
-
-    @Test
-    public void test0() throws Exception {
-        wxGzhService.handlePublicMsg(null);
+        WxForeverCode wxForeverCode = wxForeverCodeService.getOne(new QueryWrapper<WxForeverCode>().eq("openid","ovKTX59nu0GOh8OBm_OHBIeC1vuI"));
+        iWxMessageEvenService.gainTicketEvent("ovKTX59nu0GOh8OBm_OHBIeC1vuI",wxGzhService.getGzhToken(),true,wxForeverCode);
     }
 
-    @Test
-    public void test1() throws Exception {
-        try {
-            OutputStream out = new FileOutputStream("D:\\分类专题.xls");
-            List<QuestionInfoExcelTypeVo> questionInfoExcelTypeVos = questionInfoMapper.selectIssueType1(1);
-            String[] headers = { "id", "number", "issue", "image","excell_issue_name", "class_issue_name" ,"seque_issue_name","place_issue_name","question_type","class_sort"};
-            HSSFWorkbook workbook = new HSSFWorkbook();
-            for (int index=0; index < questionInfoExcelTypeVos.size();index++){
-                try {
-                    QuestionInfoExcelTypeVo questionInfoExcelTypeVo =  questionInfoExcelTypeVos.get(index);
-                    List<QuestionInfoExcelVo> questionInfoExcelVos = questionInfoMapper.selecQuestionInfoExcel1(questionInfoExcelTypeVo.getTypeId());
-                    exportExcel(workbook, index,questionInfoExcelTypeVo.getTitle().replaceAll("/","|") , headers, questionInfoExcelVos, out);
-                } catch (Exception e) {
-                    e.printStackTrace();
-                }
-            }
-            //原理就是将所有的数据一起写入,然后再关闭输入流。
-            workbook.write(out);
-            out.close();
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
-    }
 
-    @Test
-    public void test2() throws Exception {
-        try {
-            OutputStream out = new FileOutputStream("D:\\精选专题.xls");
-            List<QuestionInfoExcelTypeVo> questionInfoExcelTypeVos = questionInfoMapper.selectIssueType2(1);
-            String[] headers = { "id", "number", "issue", "image","excell_issue_name", "class_issue_name" ,"seque_issue_name","place_issue_name","question_type","class_sort"};
-            HSSFWorkbook workbook = new HSSFWorkbook();
-            for (int index=0; index < questionInfoExcelTypeVos.size();index++){
-                try {
-                    QuestionInfoExcelTypeVo questionInfoExcelTypeVo =  questionInfoExcelTypeVos.get(index);
-                    List<QuestionInfoExcelVo> questionInfoExcelVos = questionInfoMapper.selecQuestionInfoExcel2(questionInfoExcelTypeVo.getTypeId());
-                    exportExcel(workbook, index,questionInfoExcelTypeVo.getTitle().replaceAll("/","|") , headers, questionInfoExcelVos, out);
-                } catch (Exception e) {
-                    e.printStackTrace();
-                }
-            }
-            //原理就是将所有的数据一起写入,然后再关闭输入流。
-            workbook.write(out);
-            out.close();
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
-    }
 
-    @Test
-    public void test3() throws Exception {
-        try {
-            OutputStream out = new FileOutputStream("D:\\地方专题.xls");
-            List<QuestionInfoExcelTypeVo> questionInfoExcelTypeVos = questionInfoMapper.selectIssueType3(1);
-            String[] headers = { "id", "number", "issue", "image","excell_issue_name", "class_issue_name" ,"seque_issue_name","place_issue_name","question_type","class_sort"};
-            HSSFWorkbook workbook = new HSSFWorkbook();
-            for (int index=0; index < questionInfoExcelTypeVos.size();index++){
-                try {
-                    QuestionInfoExcelTypeVo questionInfoExcelTypeVo =  questionInfoExcelTypeVos.get(index);
-                    List<QuestionInfoExcelVo> questionInfoExcelVos = questionInfoMapper.selecQuestionInfoExcel3(questionInfoExcelTypeVo.getTypeId());
-                    exportExcel(workbook, index,questionInfoExcelTypeVo.getTitle().replaceAll("/","|") , headers, questionInfoExcelVos, out);
-                } catch (Exception e) {
-                    e.printStackTrace();
-                }
-            }
-            //原理就是将所有的数据一起写入,然后再关闭输入流。
-            workbook.write(out);
-            out.close();
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
-    }
 
-    @Test
-    public void test4() throws Exception {
-        try {
-            OutputStream out = new FileOutputStream("D:\\顺序练习.xls");
-            List<QuestionInfoExcelTypeVo> questionInfoExcelTypeVos = questionInfoMapper.selectIssueType4(1);
-            String[] headers = { "id", "number", "issue", "image","excell_issue_name", "class_issue_name" ,"seque_issue_name","place_issue_name","question_type","class_sort"};
-            HSSFWorkbook workbook = new HSSFWorkbook();
-            for (int index=0; index < questionInfoExcelTypeVos.size();index++){
-                try {
-                    QuestionInfoExcelTypeVo questionInfoExcelTypeVo =  questionInfoExcelTypeVos.get(index);
-                    List<QuestionInfoExcelVo> questionInfoExcelVos = questionInfoMapper.selecQuestionInfoExcel4(questionInfoExcelTypeVo.getTypeId());
-                    exportExcel(workbook, index,questionInfoExcelTypeVo.getTitle().replaceAll("/","|") , headers, questionInfoExcelVos, out);
-                } catch (Exception e) {
-                    e.printStackTrace();
-                }
-            }
-            //原理就是将所有的数据一起写入,然后再关闭输入流。
-            workbook.write(out);
-            out.close();
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
-    }
 
 
 
-    /**
-     * @Title: exportExcel
-     * @Description: 导出Excel的方法
-     * @author: evan @ 2014-01-09
-     * @param workbook
-     * @param sheetNum (sheet的位置,0表示第一个表格中的第一个sheet)
-     * @param sheetTitle  (sheet的名称)
-     * @param headers    (表格的标题)
-     * @param result   (表格的数据)
-     * @param out  (输出流)
-     * @throws Exception
-     */
-    public void exportExcel(HSSFWorkbook workbook, int sheetNum,
-                            String sheetTitle, String[] headers, List<QuestionInfoExcelVo> result,
-                            OutputStream out) throws Exception {
-        // 生成一个表格
-        HSSFSheet sheet = workbook.createSheet();
-        workbook.setSheetName(sheetNum, sheetTitle);
-        // 设置表格默认列宽度为20个字节
-        sheet.setDefaultColumnWidth((short) 20);
-        // 生成一个样式
-        HSSFCellStyle style = workbook.createCellStyle();
-        // 把字体应用到当前的样式
-        // 指定当单元格内容显示不下时自动换行
-        style.setWrapText(true);
-
-        // 产生表格标题行
-        HSSFRow row = sheet.createRow(0);
-        for (int i = 0; i < headers.length; i++) {
-            HSSFCell cell = row.createCell((short) i);
-
-            cell.setCellStyle(style);
-            HSSFRichTextString text = new HSSFRichTextString(headers[i]);
-            cell.setCellValue(text.toString());
-        }
-        // 遍历集合数据,产生数据行
-        if (result != null) {
-            int index =1;
-            for (QuestionInfoExcelVo vo : result) {
-                row = sheet.createRow(index);
-                HSSFCell cell = row.createCell(0);
-                cell.setCellValue(vo.getId());
-                cell = row.createCell(1);
-                cell.setCellValue(vo.getNumber());
-                cell = row.createCell(2);
-                cell.setCellValue(vo.getIssue());
-                cell = row.createCell(3);
-                cell.setCellValue(vo.getImage());
-                cell = row.createCell(4);
-                cell.setCellValue(vo.getExcellIssueName());
-                cell = row.createCell(5);
-                cell.setCellValue(vo.getClassIssueName());
-                cell = row.createCell(6);
-                cell.setCellValue(vo.getSequeIssueName());
-                cell = row.createCell(7);
-                cell.setCellValue(vo.getPlaceIssueName());
-                cell = row.createCell(8);
-                cell.setCellValue(vo.getQuestionType());
-                cell = row.createCell(9);
-                cell.setCellValue("");
-                index++;
-            }
-        }
-    }
 
 
 

+ 7 - 15
twzd-service/src/main/java/com/miaxis/wx/service/impl/WxMessageEvenServiceImpl.java

@@ -123,11 +123,6 @@ public class WxMessageEvenServiceImpl implements IWxMessageEvenService {
         //发送客服信息
         messageCustomSend(fromUserName,token);
 
-        // 根据fromUserName查询缓存 判断用户推广码是否过期
-//        if (redisTemplate.hasKey(Constants.GZH_MATERIAL_KEY + fromUserName)){
-//            String mediaId = (String) redisTemplate.opsForValue().get(Constants.GZH_MATERIAL_KEY + fromUserName);
-//            return mediaId;
-//        }
         String url = null ;
         if (wxForeverCode != null && wxForeverCode.getUrl() != null){
             url = wxForeverCode.getUrl();
@@ -169,11 +164,11 @@ public class WxMessageEvenServiceImpl implements IWxMessageEvenService {
         );
 
         ImgUtil.pressImage(
-                FileUtil.file(ticketPath+"jinpai.jpg"),
+                FileUtil.file(ticketPath+"jinpai2.jpg"),
                 FileUtil.file(ticketPath+fromUserName+"_img.jpg"),
                 ImgUtil.read(FileUtil.file(ticketPath+fromUserName+".jpg")), //水印图片
-                0, //x坐标修正值。 默认在中间,偏移量相对于中间偏移
-                -340, //y坐标修正值。 默认在中间,偏移量相对于中间偏移
+                -230, //x坐标修正值。 默认在中间,偏移量相对于中间偏移
+                200, //y坐标修正值。 默认在中间,偏移量相对于中间偏移
                 1.0f
         );
 
@@ -182,8 +177,8 @@ public class WxMessageEvenServiceImpl implements IWxMessageEvenService {
                 FileUtil.file(ticketPath+fromUserName+"_text1.jpg"),
                 userInfo.getString("nickname"), Color.black, //文字
                 new Font("黑体", Font.BOLD, 30), //字体
-                0, //x坐标修正值。 默认在中间,偏移量相对于中间偏移
-                -500, //y坐标修正值。 默认在中间,偏移量相对于中间偏移
+                -170, //x坐标修正值。 默认在中间,偏移量相对于中间偏移
+                500, //y坐标修正值。 默认在中间,偏移量相对于中间偏移
                 1.0f//透明度:alpha 必须是范围 [0.0, 1.0] 之内(包含边界值)的一个浮点数字
         );
 
@@ -200,8 +195,8 @@ public class WxMessageEvenServiceImpl implements IWxMessageEvenService {
                 FileUtil.file(ticketPath+fromUserName+"_text2.jpg"),
                 "二维码有效期:"+dateStr, Color.black, //文字
                 new Font("黑体", Font.BOLD, 28), //字体
-                0, //x坐标修正值。 默认在中间,偏移量相对于中间偏移
-                -80, //y坐标修正值。 默认在中间,偏移量相对于中间偏移
+                -230, //x坐标修正值。 默认在中间,偏移量相对于中间偏移
+                380, //y坐标修正值。 默认在中间,偏移量相对于中间偏移
                 1.0f//透明度:alpha 必须是范围 [0.0, 1.0] 之内(包含边界值)的一个浮点数字
         );
 
@@ -215,9 +210,6 @@ public class WxMessageEvenServiceImpl implements IWxMessageEvenService {
             JSONObject resultJSON = JSONObject.parseObject(result);
             log.info("------result:" + resultJSON);
 
-            //缓存用户推广码相关信息
-//            redisTemplate.opsForValue().set(Constants.GZH_TICKET_KEY+jsonStr.getString("ticket"),fromUserName,259200, TimeUnit.SECONDS);
-//            redisTemplate.opsForValue().set(Constants.GZH_MATERIAL_KEY+fromUserName,resultJSON.getString("media_id"),259200, TimeUnit.SECONDS);
 
             //删除服务器文件
             File imgFile = new File(ticketPath + fromUserName+"_img.jpg");