-
Notifications
You must be signed in to change notification settings - Fork 635
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
456 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
wk-app/wk-web/src/main/java/cn/wizzer/app/web/commons/quartz/job/TestJob.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package cn.wizzer.app.web.commons.quartz.job; | ||
|
||
import cn.wizzer.app.sys.modules.models.Sys_task; | ||
import org.nutz.dao.Chain; | ||
import org.nutz.dao.Cnd; | ||
import org.nutz.dao.Dao; | ||
import org.nutz.ioc.loader.annotation.Inject; | ||
import org.nutz.ioc.loader.annotation.IocBean; | ||
import org.nutz.log.Log; | ||
import org.nutz.log.Logs; | ||
import org.quartz.Job; | ||
import org.quartz.JobDataMap; | ||
import org.quartz.JobExecutionContext; | ||
import org.quartz.JobExecutionException; | ||
|
||
/** | ||
* Created by Wizzer.cn on 2015/6/27. | ||
*/ | ||
@IocBean | ||
public class TestJob implements Job { | ||
|
||
private static final Log log = Logs.get(); | ||
@Inject | ||
protected Dao dao; | ||
|
||
public void execute(JobExecutionContext context) throws JobExecutionException { | ||
JobDataMap data = context.getJobDetail().getJobDataMap(); | ||
String taskId = context.getJobDetail().getKey().getName(); | ||
String hi = data.getString("hi"); | ||
log.info("Test Job hi::" + hi); | ||
dao.update(Sys_task.class, Chain.make("exeAt", (int) (System.currentTimeMillis() / 1000)).add("exeResult", "执行成功"), Cnd.where("id", "=", taskId)); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
wk-app/wk-web/src/main/java/cn/wizzer/app/web/commons/services/email/EmailService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package cn.wizzer.app.web.commons.services.email; | ||
|
||
import org.apache.commons.mail.HtmlEmail; | ||
import org.nutz.ioc.Ioc; | ||
import org.nutz.ioc.loader.annotation.Inject; | ||
import org.nutz.ioc.loader.annotation.IocBean; | ||
import org.nutz.log.Log; | ||
import org.nutz.log.Logs; | ||
|
||
/** | ||
* Created by Wizzer on 2016/7/31. | ||
*/ | ||
@IocBean | ||
public class EmailService { | ||
private static final Log log = Logs.get(); | ||
|
||
@Inject("refer:$ioc") | ||
protected Ioc ioc; | ||
|
||
public boolean send(String to, String subject, String html) { | ||
try { | ||
HtmlEmail email = ioc.get(HtmlEmail.class); | ||
email.setSubject(subject); | ||
email.setHtmlMsg(html); | ||
email.addTo(to); | ||
email.buildMimeMessage(); | ||
email.sendMimeMessage(); | ||
return true; | ||
} catch (Throwable e) { | ||
log.info("send email fail", e); | ||
return false; | ||
} | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
wk-app/wk-web/src/main/java/cn/wizzer/app/web/commons/services/qrcode/QrcodeService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package cn.wizzer.app.web.commons.services.qrcode; | ||
|
||
import com.google.zxing.BarcodeFormat; | ||
import com.google.zxing.EncodeHintType; | ||
import com.google.zxing.MultiFormatWriter; | ||
import com.google.zxing.WriterException; | ||
import com.google.zxing.client.j2se.MatrixToImageWriter; | ||
import com.google.zxing.common.BitMatrix; | ||
import org.nutz.ioc.loader.annotation.IocBean; | ||
import org.nutz.lang.Strings; | ||
import org.nutz.log.Log; | ||
import org.nutz.log.Logs; | ||
import org.nutz.mvc.view.HttpStatusView; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
/** | ||
* Created by Wizzer on 2016/7/31. | ||
*/ | ||
@IocBean | ||
public class QrcodeService { | ||
private static final Log log = Logs.get(); | ||
|
||
protected MultiFormatWriter writer = new MultiFormatWriter(); | ||
public Object get(String data, int w, int h) { | ||
if (Strings.isBlank(data)) | ||
return new HttpStatusView(404); | ||
// 修正长宽 | ||
if (w < 1) | ||
w = 256; | ||
else if (w > 1024) | ||
w = 1024; | ||
if (h < 1) | ||
h = 256; | ||
else if (h > 1024) | ||
h = 1024; | ||
// 接受Base64编码,例如内容是中文 | ||
byte[] tmp = data.getBytes(); | ||
if (tmp != null) | ||
data = new String(tmp); | ||
try { | ||
Map<EncodeHintType, Object> hints = new HashMap<EncodeHintType, Object>(); | ||
hints.put(EncodeHintType.CHARACTER_SET, "utf-8"); | ||
BitMatrix matrix = writer.encode(data, BarcodeFormat.QR_CODE, w, h, hints); | ||
return MatrixToImageWriter.toBufferedImage(matrix); | ||
} catch (WriterException e) { | ||
// 生成失败,一般是文本太长,指定的尺寸放不下 | ||
log.debug("qrcode write fail", e); | ||
return new HttpStatusView(500); | ||
} | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
wk-app/wk-web/src/main/java/cn/wizzer/app/web/commons/services/wx/TplService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package cn.wizzer.app.web.commons.services.wx; | ||
|
||
import cn.wizzer.app.wx.modules.models.Wx_tpl_id; | ||
import cn.wizzer.app.wx.modules.models.Wx_tpl_log; | ||
import cn.wizzer.app.wx.modules.models.Wx_user; | ||
import cn.wizzer.app.wx.modules.services.WxConfigService; | ||
import cn.wizzer.app.wx.modules.services.WxTplIdService; | ||
import cn.wizzer.app.wx.modules.services.WxTplLogService; | ||
import cn.wizzer.app.wx.modules.services.WxUserService; | ||
import org.nutz.dao.Cnd; | ||
import org.nutz.ioc.loader.annotation.Inject; | ||
import org.nutz.ioc.loader.annotation.IocBean; | ||
import org.nutz.json.Json; | ||
import org.nutz.weixin.bean.WxTemplateData; | ||
import org.nutz.weixin.spi.WxApi2; | ||
import org.nutz.weixin.spi.WxResp; | ||
|
||
import java.util.Map; | ||
|
||
/** | ||
* Created by wizzer on 2016/8/6. | ||
*/ | ||
@IocBean | ||
public class TplService { | ||
@Inject | ||
private WxTplIdService wxTplIdService; | ||
@Inject | ||
private WxUserService wxUserService; | ||
@Inject | ||
private WxTplLogService wxTplLogService; | ||
@Inject | ||
private WxConfigService wxConfigService; | ||
|
||
/** | ||
* 通过模板编号发送模板消息,并记录到日志表 | ||
* | ||
* @param wxid | ||
* @param openid | ||
* @param tplId | ||
* @param url | ||
* @param data | ||
* @return | ||
*/ | ||
public String send(String wxid, String openid, String tplId, String url, Map<String, WxTemplateData> data) { | ||
WxApi2 wxApi2 = wxConfigService.getWxApi2(wxid); | ||
Wx_tpl_id tpl = wxTplIdService.fetch(tplId); | ||
if (tpl != null) { | ||
WxResp wxResp = wxApi2.template_send(openid, tpl.getTemplate_id(), url, data); | ||
Wx_user user = wxUserService.fetch(Cnd.where("openid", "=", openid)); | ||
Wx_tpl_log l = new Wx_tpl_log(); | ||
l.setWxid(wxid); | ||
l.setOpenid(openid); | ||
l.setNickname(""); | ||
if (user != null) { | ||
l.setNickname(user.getNickname()); | ||
} | ||
l.setContent(Json.toJson(data)); | ||
if (wxResp.errcode() == 0) { | ||
l.setStatus(1);//发送成功 | ||
} else l.setStatus(2);//发送失败 | ||
Wx_tpl_log rl = wxTplLogService.insert(l); | ||
return rl == null ? null : rl.getId(); | ||
} | ||
return null; | ||
} | ||
} |
Oops, something went wrong.