|
@@ -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++;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
|
|
|
|