{"id":34061,"date":"2024-11-25T11:39:27","date_gmt":"2024-11-25T03:39:27","guid":{"rendered":"https:\/\/fwq.ai\/blog\/34061\/"},"modified":"2024-11-25T11:39:27","modified_gmt":"2024-11-25T03:39:27","slug":"%e5%b0%8f%e7%a8%8b%e5%ba%8f%e9%9b%86%e6%88%90%e7%8e%af%e4%bf%a1im%e6%80%8e%e4%b9%88%e7%94%a8%ef%bc%9f%ef%bc%88%e9%99%84%e4%bb%a3%e7%a0%81%e5%ae%9e%e4%be%8b%ef%bc%89","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/34061\/","title":{"rendered":"\u5c0f\u7a0b\u5e8f\u96c6\u6210\u73af\u4fe1IM\u600e\u4e48\u7528\uff1f\uff08\u9644\u4ee3\u7801\u5b9e\u4f8b\uff09"},"content":{"rendered":"<p><strong>\u5c0f\u7a0b\u5e8f\u96c6\u6210\u73af\u4fe1IM<\/strong> <\/p>\n<p>\u6700\u8fd1\u5728\u505a\u4e00\u6b3e\u6709\u8bed\u97f3\u76f4\u64ad\u529f\u80fd\u7684\u5c0f\u7a0b\u5e8f\uff0c\u7528\u5230\u4e86\u73af\u4fe1im\u96c6\u6210\u529f\u80fd\uff0c\u7531\u4e8e\u6211\u641c\u4e86\u4e0b\u76ee\u524d\u7528\u73af\u4fe1\u505a\u5c0f\u7a0b\u5e8f\u7684\u7684\u786e\u662f\u5c11\u4e4b\u53c8\u5c11\uff0c\u800c\u4e14\u73af\u4fe1\u5b98\u65b9\u8bf4\u4ece2\u6708\u4efd\u4e0d\u518d\u66f4\u65b0\u4ee3\u7801\uff08\u5177\u4f53\u539f\u56e0\u6211\u4e5f\u6ca1\u95ee\uff0c\u53ef\u80fd\u672c\u8eab\u5fae\u4fe1\u5c31\u662f\u4e00\u6b3e\u804a\u5929\u5de5\u5177\u6240\u4ee5\u7528\u5904\u4e0d\u5927\uff09<\/p>\n<p>\u6211\u4eec\u4ea7\u54c1\u9700\u8981\u7528\u5230\u804a\u5929\u5ba4\u529f\u80fd\uff0c\u4e4b\u524d\u505aH5\u7aef\u767b\u5f55\u5b8c\u6210\u4e4b\u540e\u52a0\u5165\u804a\u5929\u5ba4\u5373\u53ef\uff1a<\/p>\n<pre> WebIM.conn.open(options);\n WebIM.conn.joinChatRoom(option1);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u540c\u6837\u65b9\u6cd5\u5728\u5c0f\u7a0b\u5e8f\u4e0a\u4e0d\u884c\uff0c\u4e00\u76f4\u62a5\u9519\uff1a<\/p>\n<pre>Cannot read property 'sendIQ' of undefined<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u767e\u5ea6\u4e86\u4e00\u4e0b\uff0c\u8bf4\u52a0\u5165\u804a\u5929\u5ba4\u8981\u653e\u5728\u767b\u5f55\u6210\u529f\u540e\u7684\u56de\u8c03\u91cc\uff0c\u4e8e\u662f\u67e5\u770b\u5b83\u7684\u6e90\u7801connection.js\u53d1\u73b0:<\/p>\n<pre>connection.prototype.open = function (options) {\n\n\n    var pass = _validCheck(options, this);\n\n    if (!pass) {\n        return;\n    }\n    var conn = this;\n\n    if (conn.isOpening() || conn.isOpened()) {\n        return;\n    }\n\n    if (options.accessToken) {\n        options.access_token = options.accessToken;\n        _login(options, conn);\n    } else {\n       \/\/\u767b\u5f55\u6210\u529f\u7684\u56de\u8c03\u51fd\u6570\n        var suc = function (data, xhr, myName) {\n            conn.context.status = _code.STATUS_DOLOGIN_IM;\n            conn.context.restTokenData = data;\n            if (data.statusCode != '404' &amp;&amp; data.statusCode != '400') {\n                wx.showToast({\n                    title: '\u767b\u5f55\u6210\u529f',\n                    icon: 'none',\n                    duration: 4000\n                });\n            }\n            \/\/\u56de\u8c03\u6210\u529f\u540e\u6267\u884c\u8fd9\u4e2a\u65b9\u6cd5\n            _login(data.data, conn);\n           \n        };\n        \n        var options = {\n            url: apiUrl + '\/' + orgName + '\/' + appName + '\/token',\n            data: loginfo,\n             success: suc || _utils.emptyfn,\n            error: error || _utils.emptyfn\n        };\n        _utils.ajax(options);\n    }<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u767b\u5f55\u6210\u529f\u6709\u4e00\u4e2a\u5185\u90e8\u56de\u8c03\uff0c\u56de\u8c03\u91cc\u9762\u8c03\u7528\u4e86\u4e00\u4e2a _login(data.data, conn)\u7684\u65b9\u6cd5\uff1a<\/p>\n<pre>\/\/\u5177\u4f53\u91cc\u9762\u6267\u884c\u4ec0\u4e48\u53bb\u6e90\u4ee3\u7801\u67e5\u770b\uff0c\u6211\u5c31\u4e0d\u8d34\u4ee3\u7801\u4e86\nvar _login = function (options, conn) {\n    \n    var callback = function (status, msg) {\n      _loginCallback(status, msg, conn);\n    };\n\n\n};<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u6267\u884c\u5b8clogin\u65b9\u6cd5\u6709\u4e00\u4e2a_loginCallback\u56de\u8c03\uff1a<\/p>\n<pre>var _loginCallback = function (status, msg, conn) {\n    var conflict, error;\n    \/\/console.log('_loginCallback 1', Strophe.Status, status, msg)\n    if (msg === 'conflict') {\n        conflict = true;\n    }\n    console.log(status)\n    if (status == Strophe.Status.CONNFAIL) {\n     \n    } else if (status == Strophe.Status.ATTACHED || status == Strophe.Status.CONNECTED) {\n      \/\/\u767b\u5f55\u6210\u529f\n       \n    } else if (status == Strophe.Status.DISCONNECTING) {\n  \n    } else if (status == Strophe.Status.DISCONNECTED) {\n      \n    } else if (status == Strophe.Status.AUTHFAIL) {\n     \n    } else if (status == Strophe.Status.ERROR) {\n\n    }\n    conn.context.status_now = status;\n};<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u901a\u8fc7\u65ad\u70b9\u53d1\u73b0\u5f53\u6267\u884c\u5230 <strong>else if (status == Strophe.Status.ATTACHED || status == Strophe.Status.CONNECTED)<\/strong>\u65f6\uff0c\u767b\u5f55\u6210\u529f.\u6240\u4ee5\u9700\u8981\u628a\u52a0\u5165\u804a\u5929\u5ba4\u7684\u56de\u8c03\u9700\u8981\u653e\u5728\u8fd9\u4e2a\u5224\u65ad\u91cc\u9762,\u6211\u7684\u5177\u4f53\u505a\u6cd5\u5982\u4e0b\uff1a<\/p>\n<pre>\/\/\u9879\u76ee\u4e2d\u5c01\u88c5\u4e00\u4e2a\u52a0\u5165\u804a\u5929\u5ba4\u51fd\u6570\n joinRoom: function () {\n    var option1 = {};\n    var option2 = {};\n    \/\/\u52a0\u5165\u804a\u5929\u5ba4\n    WebIM.conn.joinChatRoom(option1);\n    WebIM.conn.joinChatRoom(option2);\n  }\uff1b\n   \/\/\u5728\u73af\u4fe1\u767b\u5f55\u51fd\u6570\u4e2d\u6dfb\u52a0\u4e00\u4e2a\u81ea\u5df1\u7684\u56de\u8c03\uff1a\n    var options = {\n      apiUrl: WebIM.config.apiURL,\n      user: userId + '',\n      pwd: userId + '',\n      grant_type: \"password\",\n      appKey: WebIM.config.appkey,\n      \/\/\u81ea\u5df1\u6dfb\u52a0\u7684\u56de\u8c03\u51fd\u6570\n      callBack:function(){\n      \/\/\u8c03\u7528\u52a0\u5165\u804a\u5929\u5ba4\n        that.joinRoom();\n      }\n    };\n    WebIM.conn.open(options);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4fee\u6539\u73af\u4fe1connection.js\u4ee3\u7801\uff1a<\/p>\n<pre>\/\/\u767b\u5f55\u4ee3\u7801\nconnection.prototype.open = function (options) {\n\n        var suc = function (data, xhr, myName) {\n            \/\/callBack\u4f20\u5165\u52a0\u5165\u804a\u5929\u5ba4\u56de\u8c03\n            _login(data.data, conn, options.callBack);\n        };\n        var options = {\n            url: apiUrl + '\/' + orgName + '\/' + appName + '\/token',\n            data: loginfo,\n             success: suc || _utils.emptyfn,\n             \/\/\u6dfb\u52a0\u52a0\u5165\u804a\u5929\u5ba4\u7684\u56de\u8c03\u51fd\u6570\n             callBack: options.callBack,\n            error: error || _utils.emptyfn\n        };\n    }\n};\n\/\/_login\u4ee3\u7801\nvar _login = function (options, conn, callBack) {\n     \n    var callback = function (status, msg) {\n    \/\/\u628a\u52a0\u5165\u804a\u5929\u5ba4\u51fd\u6570\u4f20\u7ed9_login\u56de\u8c03\u51fd\u6570\n      _loginCallback(status, msg, conn, callBack);\n    };\n};\n\/\/_loginCallback\u4ee3\u7801\nvar _loginCallback = function (status, msg, conn,callBack) {\n    var conflict, error;\n    \/\/console.log('_loginCallback 1', Strophe.Status, status, msg)\n    if (msg === 'conflict') {\n        conflict = true;\n    }\n    console.log(status)\n    if (status == Strophe.Status.CONNFAIL) {\n     \n    } else if (status == Strophe.Status.ATTACHED || status == Strophe.Status.CONNECTED) {\n      \/\/\u767b\u5f55\u6210\u529f\u6267\u884c\u52a0\u5165\u804a\u5929\u5ba4\n       callBack();\n    } else if (status == Strophe.Status.DISCONNECTING) {\n  \n    } else if (status == Strophe.Status.DISCONNECTED) {\n      \n    } else if (status == Strophe.Status.AUTHFAIL) {\n     \n    } else if (status == Strophe.Status.ERROR) {\n\n    }\n    conn.context.status_now = status;\n};<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5177\u4f53\u601d\u8def\u5c31\u662f\u8fd9\u6837\uff0c\u7531\u4e8e\u73af\u4fe1\u5c0f\u7a0b\u5e8f\u4ee3\u7801\u6709\u5f88\u591a\u5751\uff0c\u6240\u4ee5\u9047\u5230\u95ee\u9898\u591a\u770b\u770b\u6e90\u7801\uff0c\u6709\u4e9b\u529f\u80fd\u5c31\u9700\u8981\u81ea\u5df1\u53bb\u4fee\u6539\u4ee3\u7801\uff0c\u8fd9\u662f\u73af\u4fe1\u5de5\u5355\u56de\u7b54\u6211\u7684\u95ee\u9898\uff1a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/image\/205\/376\/805\/1632216098327305.png\" class=\"aligncenter\" title=\"\u5c0f\u7a0b\u5e8f\u96c6\u6210\u73af\u4fe1IM\u600e\u4e48\u7528\uff1f\uff08\u9644\u4ee3\u7801\u5b9e\u4f8b\uff09\u63d2\u56fe\" alt=\"\u5c0f\u7a0b\u5e8f\u96c6\u6210\u73af\u4fe1IM\u600e\u4e48\u7528\uff1f\uff08\u9644\u4ee3\u7801\u5b9e\u4f8b\uff09\u63d2\u56fe\" \/><\/p>\n<p>\u76f8\u5173\u5b66\u4e60\u63a8\u8350\uff1a<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5c0f\u7a0b\u5e8f\u96c6\u6210\u73af\u4fe1IM\u600e\u4e48\u7528\uff1f\uff08\u9644\u4ee3\u7801\u5b9e\u4f8b\uff09\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5c0f\u7a0b\u5e8f\u96c6\u6210\u73af\u4fe1IM \u6700\u8fd1\u5728\u505a\u4e00\u6b3e\u6709\u8bed\u97f3\u76f4\u64ad\u529f\u80fd\u7684\u5c0f\u7a0b\u5e8f\uff0c\u7528\u5230\u4e86\u73af\u4fe1im\u96c6\u6210\u529f\u80fd\uff0c\u7531\u4e8e\u6211\u641c\u4e86\u4e0b\u76ee\u524d\u7528\u73af\u4fe1\u505a\u5c0f\u7a0b\u5e8f\u7684\u7684\u786e\u662f\u5c11\u4e4b\u53c8\u5c11\uff0c\u800c\u4e14\u73af\u4fe1\u5b98\u65b9\u8bf4\u4ece2\u6708\u4efd\u4e0d\u518d\u66f4\u65b0\u4ee3\u7801\uff08\u5177\u4f53\u539f\u56e0\u6211\u4e5f\u6ca1\u95ee\uff0c\u53ef\u80fd\u672c\u8eab\u5fae\u4fe1\u5c31\u662f\u4e00\u6b3e\u804a\u5929\u5de5\u5177\u6240\u4ee5\u7528\u5904\u4e0d\u5927\uff09 \u6211\u4eec\u4ea7\u54c1\u9700\u8981\u7528\u5230\u804a\u5929\u5ba4\u529f\u80fd\uff0c\u4e4b\u524d\u505aH5\u7aef\u767b\u5f55\u5b8c\u6210\u4e4b\u540e\u52a0\u5165\u804a\u5929\u5ba4\u5373\u53ef\uff1a WebIM.conn.open(options); WebIM.conn.joinChatRoom(option1); \u767b\u5f55\u540e\u590d\u5236 \u540c\u6837\u65b9\u6cd5\u5728\u5c0f\u7a0b\u5e8f\u4e0a\u4e0d\u884c\uff0c\u4e00\u76f4\u62a5\u9519\uff1a Cannot read property &#8216;sendIQ&#8217; of undefined \u767b\u5f55\u540e\u590d\u5236 \u767e\u5ea6\u4e86\u4e00\u4e0b\uff0c\u8bf4\u52a0\u5165\u804a\u5929\u5ba4\u8981\u653e\u5728\u767b\u5f55\u6210\u529f\u540e\u7684\u56de\u8c03\u91cc\uff0c\u4e8e\u662f\u67e5\u770b\u5b83\u7684\u6e90\u7801connection.js\u53d1\u73b0: connection.prototype.open = function (options) { var pass = _validCheck(options, this); if (!pass) { return; } var conn = this; if (conn.isOpening() || conn.isOpened()) { return; } if (options.accessToken) { options.access_token = options.accessToken; _login(options, conn); } else { \/\/\u767b\u5f55\u6210\u529f\u7684\u56de\u8c03\u51fd\u6570 var suc [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19],"tags":[],"class_list":["post-34061","post","type-post","status-publish","format-standard","hentry","category-19"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/34061","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=34061"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/34061\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=34061"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=34061"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=34061"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}