微信小程式 智慧型聊天 機械人 OLAMI

2021-09-04 04:20:13 字數 2004 閱讀 4698

效果見:

一、首先引入對應自然語言語義互動對應的介面api需要的用到的md5.js,用於加密驗籤。

//md5加密演算法

function md5(string)

var temp = wordtohex(a) + wordtohex(b) + wordtohex(c) + wordtohex(d);

return temp.tolowercase();

}function rotateleft(lvalue, ishiftbits)

function addunsigned(lx, ly)

if (lx4 | ly4) else

} else

}function f(x, y, z)

function g(x, y, z)

function h(x, y, z)

function i(x, y, z)

function ff(a, b, c, d, x, s, ac)

function gg(a, b, c, d, x, s, ac)

function hh(a, b, c, d, x, s, ac)

function ii(a, b, c, d, x, s, ac)

function converttowordarray(string)

lwordcount = (lbytecount - (lbytecount % 4)) / 4;

lbyteposition = (lbytecount % 4) * 8;

lwordarray[lwordcount] = lwordarray[lwordcount] | (0x80 << lbyteposition);

lwordarray[lnumberofwords - 2] = lmessagelength << 3;

lwordarray[lnumberofwords - 1] = lmessagelength >>> 29;

return lwordarray;

}function wordtohex(lvalue)

return wordtohexvalue;

}function utf8encode(string) else if ((c > 127) && (c < 2048)) else

} return utftext;

}module.exports =

二、封裝olami對應api介面需要的引數(以下只是**片段,僅供參考)

var md5 = require('../index/md5.js');

const requesturl = "";

const api = "nli";

var timestamp = new date().gettime();

var sign = md5.md5(originalsign);

var rqdatajson = , "data_type": "stt" };

var rqdata = json.stringify(rqdatajson);

三、通過wx.request方法呼叫該api介面,解析放回值獲取自己需要的內容即可。

wx.request(,

header: ,

method: 'post',

success: function (res) )

}, 2000);

},fail: function () )

console.error('[資料庫] [查詢記錄] 失敗:', err)}})

至此就完成了人機互動的api呼叫,後面介面樣式如何進行設計,大家不盡相同,這裡面就不介紹自己如何使用的了,這裡都是自己使用過程中的一點點小總結,希望大家不走偏路,對大家有所幫助。

微信聊天機械人

import arrow import itchat import pydash import requests deflocal datetime 格式化的時間戳 return arrow.now format yyyy mm dd hh mm ss defget user info wx msg...

微信聊天機械人2019

新建乙個名為wechatrobot.py的檔案,內容如下 import urllib.parse import urllib.request from os import remove import itchat import requests from aip import aipimagecla...

微信自動聊天機械人

背景 操作步驟 操作過程 import requests import itchat 圖靈機人人的apikey key d7b92b1df4ef4ba6a6c649200208f103 defget response msg 這個位址在此處給出,一看就懂 apiurl data的本質是乙個地點,要想...