發(fā)環(huán)境及框架后端:國產(chǎn)java極速框架JFinal(超級(jí)好用有木有啊)前端:WEUI WXSS版(微信團(tuán)隊(duì)出品的,自己寫樣式不管怎么寫都丑啊)數(shù)據(jù)庫:MySQL服務(wù)器:Linux Nginx Tomcat開發(fā)流程 ...

開發(fā)環(huán)境及框架
開發(fā)流程
后端關(guān)鍵代碼詳情
2個(gè)方法,一個(gè)是接收前臺(tái)傳入的參數(shù)生成圖片并返回處理結(jié)果的,一個(gè)是獲取用戶openid時(shí)候的前置請(qǐng)求
private static final WeixinInfo weixinInfo = WeixinInfo.dao.getWeixinInfoById(5);/*** 創(chuàng)建一個(gè)接口,用戶需傳遞姓名和微信openid* 每個(gè)用戶只能創(chuàng)建一張(為服務(wù)器考慮,重復(fù)生成則覆蓋上一張)* 返回結(jié)果有fail和ok兩種*/public void getMarryPic() {Map map = new HashMap<>();String result = "fail";String openid = getPara("openid");String name = getPara("name");if (name != null && !name.equals("")) {ImgMarkUtil.mark(getRequest().getServletContext().getRealPath("/") + "/jiehun/yuan2.jpg", getRequest().getServletContext().getRealPath("/") + "jiehun/" + openid + ".jpg", name);result = "ok";map.put("imgurl", weixinInfo.get("host") + "/jiehun/" + openid + ".jpg");}map.put("result", result);renderJson(map);}public void getWxCode() {String js_code = getPara("js_code");String alipayURL = "https://api.weixin.qq.com/sns/jscode2session?";renderText(HttpUtils.post(alipayURL, "appid=" + weixinInfo.get("appid") + "&secret=" + weixinInfo.get("appsecret")+ "&grant_type=authorization_code" + "&js_code=" + js_code));}通過讀取本地原圖片,把用戶傳入的姓名弄成水印附在圖片上,隨后根據(jù)openid生成文件名。
public static void mark(String srcImgPath, String outImgPath, String waterMarkContent) {try {// 讀取原圖片信息File srcImgFile = new File(srcImgPath);Image srcImg = ImageIO.read(srcImgFile);int srcImgWidth = srcImg.getWidth(null);int srcImgHeight = srcImg.getHeight(null);// 加水印