2022-01-24 19:08:08
浏览数 (1)
demo 下载 https://download.csdn.net/download/github_35631540/12423282
初生牛犊不怕虎
山重水复疑无路
柳暗花明又一村
为伊消得人憔悴
提携玉龙为君死
代码语言:javascript
复制let WebIM = require("../../utils/WebIM")["default"];
let __test_account__, __test_psword__;
let disp = require("../../utils/broadcast");
var X2JS = require('../../sdk/x2j/x2js/we-x2js')
let XML = require('../../sdk/ObjTree');
let id = null
var islogin = false;
const btoa = require('../../sdk/base64.min').btoa
// // 这里是引用
// const {atob} = polyfill;
// // 如果你需要用btoa
// const {btoa} = polyfill;
// let JKL = require('../../sdk/jkl-dumper');
// __test_account__ = "easezy";
// __test_psword__ = "111111";
let runAnimation = true
Page({
data: {
name: "fizz",
psd: "123456",
pcto: "192.168.0.105",
grant_type: "password",
rtcUrl: ''
},
_startSocket: function () {
// var to = "win10-2020bwunu";
var to = this.data.pcto
var xmlns = "urn:ietf:params:xml:ns:xmpp-framing";
var version = "1.0";
var xmllang = "zh";
var resource = "appClient";
var from = null;
var username = this.data.name
var password = this.data.psd
console.log(this.data.name, 'this.data.name')
console.log(this.data.psd, 'this.data.psd')
console.log(this.data.pcto, 'this.data.pcto')
let socketTask = wx.connectSocket({
url: 'ws://' this.data.pcto ':7070/ws/',
protocols: ['xmpp']
})
//json转xml
function json2xml(jsonstring) {
var xotree = new XML.ObjTree();
var xml = xotree.writeXML(jsonstring);
//使用jkl-dumper.js中的formatXml方法将xml字符串格式化
//var xmlText = formatXml(xml);
return xml;
}
//xml转json
function xml2json(xmlstring) {
//将xml字符串转为json
var x2js = new X2JS();
var json = x2js.xml2js(xmlstring);
console.log('转换成json', json)
return json;
}
function connwsopen() {
from = username "@" to;
var temp = {
"open": {
"-to": to,
"-from": from,
"-xmlns": xmlns,
"-xml:lang": xmllang,
"-version": version
}
};
//转化为xml
var loginXml = null
// loginXml = `<?xml version="1.0" encoding="UTF-8" ?>
// <open to="win10-2020bwunu" from="fizz@win10-2020bwunu" xmlns="urn:ietf:params:xml:ns:xmpp-framing" xml:lang="zh" version="1.0" />`
loginXml = json2xml(temp)
socketTask.send({ data: loginXml })
}
//登录验证
function auth(authentication) {
//字符串格式是:jid password,以 作为分隔符
var temp = username "@" to "