開發環境及框架后端:國產java極速框架JFinal(超級好用有木有啊)前端:WEUI WXSS版(微信團隊出品的,自己寫樣式不管怎么寫都丑啊)數據庫:MySQL服務器:Linux Nginx Tomcat開發流程用戶 ...
開發環境及框架
開發流程
后端關鍵代碼詳情
獲取用戶發過來的信息和openid,獲得圖靈機器人的回應內容(傳入OPENID這種唯一標識,就可以產生“場景式上下文”的內容,圖靈機器人的特色之一)
public static String getTulingResult(String openid, String info){
JSONObject json = new JSONObject();
json.put("key", KEY);
json.put("userid", openid);
json.put("info", info);
String result = PostServer.SendPost(json.toString(), "http://www.tuling123.com/openapi/api");
JSONObject jsonObject = JSONObject.parseObject(result);
return jsonObject.getString("text").toString();
}
這個方法是用來發送信息給用戶的
public void render(WxAppMsg wxAppMsg) {
if (ApiConfigKit.isDevMode()) {
System.out.println("發送消息:");
System.out.println(JsonUtils.toJson(wxAppMsg));
System.out.println("--------------------------------------------------------------------------------\n");
}
String at = AccessTokenApi.getAccessToken().getAccessToken();
String url = "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token="+at;
Map map= new HashMap<>();
map.put("touser",wxAppMsg.getTouser());
map.put("msgtype","text");
map.put("text",wxAppMsg.getText());
String a = HttpUtils.post(url, JsonUtils.toJson(map));
System.out.print("回調>>>>"+a);
}
小程序代碼
index.wxss
<view class="page">
<view class="page__bd" style="text-align:center">
點我聊天-》<contact-button size="27" session-from="weapp">
</contact-button>《-點我聊天
</view>
</view>
這一次前端的內容基本沒有什么內容。
這個應該算不上是教程,因為后端代碼調用了蠻多封裝好了的東西。如果開發微信小程序的后端,我個人認為可以去借鑒jfinal_weixin.