{"id":300,"date":"2026-06-25T13:33:54","date_gmt":"2026-06-25T05:33:54","guid":{"rendered":"https:\/\/wp.buildyou.top\/index.php\/2026\/06\/25\/%e5%be%ae%e4%bf%a1%e5%85%ac%e4%bc%97%e5%8f%b7%e4%b8%8e%e4%bc%81%e4%b8%9a%e5%be%ae%e4%bf%a1-access_token-%e5%8f%8a-jsapi_ticket-%e6%8e%a5%e5%8f%a3%e5%af%b9%e6%af%94%e4%b8%8e%e6%94%b9%e9%80%a0%e5%ae%9e\/"},"modified":"2026-06-25T13:34:31","modified_gmt":"2026-06-25T05:34:31","slug":"%e5%be%ae%e4%bf%a1%e5%85%ac%e4%bc%97%e5%8f%b7%e4%b8%8e%e4%bc%81%e4%b8%9a%e5%be%ae%e4%bf%a1-access_token-%e5%8f%8a-jsapi_ticket-%e6%8e%a5%e5%8f%a3%e5%af%b9%e6%af%94%e4%b8%8e%e6%94%b9%e9%80%a0%e5%ae%9e","status":"publish","type":"post","link":"https:\/\/wp.buildyou.top\/index.php\/2026\/06\/25\/%e5%be%ae%e4%bf%a1%e5%85%ac%e4%bc%97%e5%8f%b7%e4%b8%8e%e4%bc%81%e4%b8%9a%e5%be%ae%e4%bf%a1-access_token-%e5%8f%8a-jsapi_ticket-%e6%8e%a5%e5%8f%a3%e5%af%b9%e6%af%94%e4%b8%8e%e6%94%b9%e9%80%a0%e5%ae%9e\/","title":{"rendered":"\u5fae\u4fe1\u516c\u4f17\u53f7\u4e0e\u4f01\u4e1a\u5fae\u4fe1 access_token \u53ca jsapi_ticket \u63a5\u53e3\u5bf9\u6bd4\u4e0e\u6539\u9020\u5b9e\u8df5"},"content":{"rendered":"<h2>\u524d\u8a00<\/h2>\n<p>\u5728\u65e5\u5e38\u5f00\u53d1\u4e2d\uff0c\u8bb8\u591a\u5f00\u53d1\u8005\u4f1a\u6df7\u6dc6<strong>\u5fae\u4fe1\u516c\u4f17\u53f7<\/strong>\u4e0e<strong>\u4f01\u4e1a\u5fae\u4fe1<\/strong>\u7684\u63a5\u53e3\u4f53\u7cfb\u3002\u5b9e\u9645\u4e0a\uff0c\u8fd9\u4e24\u4e2a\u5e73\u53f0\u662f<strong>\u5b8c\u5168\u72ec\u7acb\u7684\u4e24\u5957\u7cfb\u7edf<\/strong>\uff0c\u4e0d\u4ec5\u63a5\u53e3\u57df\u540d\u4e0d\u540c\uff0c\u53c2\u6570\u540d\u79f0\u3001\u9274\u6743\u673a\u5236\u4e5f\u5b58\u5728\u663e\u8457\u5dee\u5f02\u3002\u672c\u6587\u5c06\u7cfb\u7edf\u5bf9\u6bd4\u4e24\u8005\u5728 <code>access_token<\/code> \u4e0e <code>jsapi_ticket<\/code> \u83b7\u53d6\u4e0a\u7684\u533a\u522b\uff0c\u5e76\u7ed9\u51fa\u4e00\u4efd\u4ece\u516c\u4f17\u53f7\u4ee3\u7801\u8fc1\u79fb\u5230\u4f01\u4e1a\u5fae\u4fe1\u7684\u5b8c\u6574\u6539\u9020\u5b9e\u8df5\u3002<\/p>\n<h2>\u4e00\u3001access_token \u63a5\u53e3\u5bf9\u6bd4<\/h2>\n<p>\u5fae\u4fe1\u516c\u4f17\u53f7\/\u5c0f\u7a0b\u5e8f\u4f7f\u7528 <code>https:\/\/api.weixin.qq.com\/cgi-bin\/token<\/code> \u83b7\u53d6\u5168\u5c40\u51ed\u636e <code>access_token<\/code>\uff0c\u800c\u4f01\u4e1a\u5fae\u4fe1\u5219\u4f7f\u7528\u5b8c\u5168\u72ec\u7acb\u7684\u57df\u540d\u548c\u8def\u5f84\u3002<\/p>\n<h3>1.1 \u6838\u5fc3\u5dee\u5f02<\/h3>\n<p>\u4e24\u8005\u7684\u6838\u5fc3\u5dee\u5f02\u96c6\u4e2d\u5728<strong>\u57df\u540d\u3001\u8bf7\u6c42\u5730\u5740\u548c\u53c2\u6570\u540d\u79f0<\/strong>\u4e09\u4e2a\u65b9\u9762\uff1a<\/p>\n<table>\n<thead>\n<tr>\n<th>\u7279\u6027<\/th>\n<th>\u5fae\u4fe1\u516c\u4f17\u53f7 \/ \u5c0f\u7a0b\u5e8f<\/th>\n<th>\u4f01\u4e1a\u5fae\u4fe1<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><strong>\u63a5\u53e3\u5730\u5740<\/strong><\/td>\n<td><code>https:\/\/api.weixin.qq.com\/cgi-bin\/token<\/code><\/td>\n<td><code>https:\/\/qyapi.weixin.qq.com\/cgi-bin\/gettoken<\/code><\/td>\n<\/tr>\n<tr>\n<td><strong>\u53c2\u6570<\/strong><\/td>\n<td><code>appid<\/code> \u548c <code>secret<\/code><\/td>\n<td><code>corpid<\/code> \u548c <code>corpsecret<\/code><\/td>\n<\/tr>\n<tr>\n<td><strong>\u4e3b\u8981\u4f7f\u7528\u573a\u666f<\/strong><\/td>\n<td>\u516c\u4f17\u53f7\u3001\u5c0f\u7a0b\u5e8f\u3001\u5f00\u653e\u5e73\u53f0<\/td>\n<td>\u4f01\u4e1a\u5fae\u4fe1\u5185\u90e8\u5e94\u7528\u3001\u7b2c\u4e09\u65b9\u5e94\u7528<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>1.2 \u8bf7\u6c42\u793a\u4f8b<\/h3>\n<p><strong>\u5fae\u4fe1\u516c\u4f17\u53f7 \/ \u5c0f\u7a0b\u5e8f<\/strong>\uff1a\u7528\u4e8e\u83b7\u53d6\u8c03\u7528\u516c\u4f17\u53f7\u3001\u5c0f\u7a0b\u5e8f\u76f8\u5173\u529f\u80fd\uff08\u5982\u6d88\u606f\u56de\u590d\u3001\u7528\u6237\u7ba1\u7406\u3001\u652f\u4ed8\u7b49\uff09\u7684\u5168\u5c40\u51ed\u8bc1\u3002<\/p>\n<pre><code>GET https:\/\/api.weixin.qq.com\/cgi-bin\/token?grant_type=client_credential&amp;appid=APPID&amp;secret=SECRET<\/code><\/pre>\n<p><strong>\u4f01\u4e1a\u5fae\u4fe1<\/strong>\uff1a\u7528\u4e8e\u83b7\u53d6\u8c03\u7528\u4f01\u4e1a\u5fae\u4fe1\u5185\u90e8\u5e94\u7528\u6216\u7b2c\u4e09\u65b9\u5e94\u7528\u63a5\u53e3\uff08\u5982\u901a\u8baf\u5f55\u7ba1\u7406\u3001\u6d88\u606f\u53d1\u9001\u3001\u6253\u5361\u6570\u636e\u7b49\uff09\u7684\u51ed\u8bc1\u3002<\/p>\n<pre><code>GET https:\/\/qyapi.weixin.qq.com\/cgi-bin\/gettoken?corpid=CORPID&amp;corpsecret=CORPSECRET<\/code><\/pre>\n<div class=\"notice\">\n<p><strong>\u26a0 \u91cd\u8981\u63d0\u9192<\/strong>\uff1a\u8fd9\u4e24\u4e2a\u5e73\u53f0\u662f\u5b8c\u5168\u72ec\u7acb\u7684\u4f53\u7cfb\uff0c<strong>\u5fae\u4fe1\u516c\u4f17\u53f7\u7684 AppId\/Secret \u65e0\u6cd5\u5728\u4f01\u4e1a\u5fae\u4fe1\u4e2d\u4f7f\u7528<\/strong>\uff0c\u53cd\u4e4b\u4ea6\u7136\u3002\u8bf7\u52a1\u5fc5\u6839\u636e\u5b9e\u9645\u5f00\u53d1\u5e73\u53f0\uff08\u516c\u4f17\u5e73\u53f0 <code>mp.weixin.qq.com<\/code> \u6216\u4f01\u4e1a\u5fae\u4fe1\u7ba1\u7406\u540e\u53f0 <code>work.weixin.qq.com<\/code>\uff09\u9009\u62e9\u5bf9\u5e94\u7684\u63a5\u53e3\u548c\u53c2\u6570\u3002<\/p>\n<\/div>\n<h2>\u4e8c\u3001jsapi_ticket \u63a5\u53e3\u5bf9\u6bd4<\/h2>\n<p>\u5fae\u4fe1\u516c\u4f17\u53f7\u901a\u8fc7 <code>https:\/\/api.weixin.qq.com\/cgi-bin\/ticket\/getticket<\/code> \u83b7\u53d6 <code>jsapi_ticket<\/code>\uff0c\u7528\u4e8e JS-SDK \u7b7e\u540d\u4e0e\u5206\u4eab\u529f\u80fd\u3002\u4f01\u4e1a\u5fae\u4fe1\u7684\u63a5\u53e3\u5730\u5740\u4e0e\u6b64\u5b8c\u5168\u4e0d\u540c\uff0c\u57df\u540d\u540c\u6837\u4ece <code>api.weixin.qq.com<\/code> \u6362\u6210\u4e86 <code>qyapi.weixin.qq.com<\/code>\u3002<\/p>\n<h3>2.1 \u6838\u5fc3\u533a\u522b\uff1a\u4e24\u5f20&#8221;\u7968&#8221;\uff0c\u5404\u53f8\u5176\u804c<\/h3>\n<p>\u4f01\u4e1a\u5fae\u4fe1\u7684 JS-SDK \u4f7f\u7528\u4e86<strong>\u4e24\u5957\u6743\u9650\u4f53\u7cfb<\/strong>\uff0c\u56e0\u6b64\u5b58\u5728\u4e24\u79cd\u4e0d\u540c\u7684 <code>jsapi_ticket<\/code>\uff0c\u5f00\u53d1\u8005\u9700\u8981\u6839\u636e\u4e1a\u52a1\u573a\u666f\u9009\u62e9\u4f7f\u7528\uff1a<\/p>\n<table>\n<thead>\n<tr>\n<th>\u7279\u6027<\/th>\n<th>\u5fae\u4fe1\u516c\u4f17\u53f7<\/th>\n<th>\u4f01\u4e1a\u5fae\u4fe1\uff08\u4f01\u4e1a\u7968\uff09<\/th>\n<th>\u4f01\u4e1a\u5fae\u4fe1\uff08\u5e94\u7528\u7968\uff09<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><strong>\u63a5\u53e3\u5730\u5740<\/strong><\/td>\n<td><code>\/cgi-bin\/ticket\/getticket<\/code><\/td>\n<td><code>\/cgi-bin\/get_jsapi_ticket<\/code><\/td>\n<td><code>\/cgi-bin\/ticket\/get<\/code><\/td>\n<\/tr>\n<tr>\n<td><strong>\u53c2\u6570<\/strong><\/td>\n<td><code>access_token<\/code><\/td>\n<td><code>access_token=ACCESS_TOKEN<\/code><\/td>\n<td><code>access_token=ACCESS_TOKEN&amp;type=agent_config<\/code><\/td>\n<\/tr>\n<tr>\n<td><strong>\u7528\u9014<\/strong><\/td>\n<td>\u8c03\u7528\u5927\u90e8\u5206 JS-SDK \u529f\u80fd\uff08\u5206\u4eab\u3001\u56fe\u50cf\u3001\u97f3\u9891\u7b49\uff09<\/td>\n<td>\u8c03\u7528<strong>\u4f01\u4e1a\u7ea7\u522b<\/strong>\u7684 JS-SDK \u63a5\u53e3\uff0c\u901a\u5e38\u4e0d\u4f9d\u8d56\u7279\u5b9a\u5e94\u7528\uff08\u5982\u9009\u62e9\u6210\u5458\uff09<\/td>\n<td>\u8c03\u7528<strong>\u7279\u5b9a\u5e94\u7528<\/strong>\u7684 JS-SDK \u63a5\u53e3\uff08\u5982 <code>agentConfig<\/code> \u914d\u7f6e\uff09\uff0c\u7528\u4e8e\u8bbf\u95ee\u5e94\u7528\u79c1\u6709\u6570\u636e\u6216\u529f\u80fd<\/td>\n<\/tr>\n<tr>\n<td><strong>\u4f7f\u7528\u573a\u666f\u4e3e\u4f8b<\/strong><\/td>\n<td>\u6240\u6709\u9700\u8981\u8c03\u7528\u5fae\u4fe1 JS-SDK \u7684\u7f51\u9875<\/td>\n<td>1. <code>wx.config<\/code> \u521d\u59cb\u5316<br \/>2. \u8c03\u7528\u57fa\u7840\u63a5\u53e3\uff08\u5982 <code>chooseImage<\/code>\u3001<code>openEnterpriseChat<\/code>\uff09<br \/>3. \u7b2c\u4e09\u65b9\u5e94\u7528\u5728\u4e3a\u6388\u6743\u4f01\u4e1a\u8fdb\u884c <code>config<\/code> \u914d\u7f6e\u65f6<\/td>\n<td>1. <code>wx.agentConfig<\/code> \u521d\u59cb\u5316<br \/>2. \u8c03\u7528\u5e94\u7528\u79c1\u6709\u63a5\u53e3\uff08\u5982\u53d1\u9001\u5e94\u7528\u6d88\u606f\u3001\u8bbf\u95ee\u5e94\u7528\u53ef\u89c1\u8303\u56f4\u5185\u7684\u901a\u8baf\u5f55\u7b49\uff09<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><em>\u6ce8\uff1a\u4ee5\u4e0a\u4f01\u4e1a\u5fae\u4fe1\u63a5\u53e3\u7684\u5b8c\u6574\u57df\u540d\u5747\u4e3a <code>https:\/\/qyapi.weixin.qq.com<\/code>\u3002<\/em><\/p>\n<h3>2.2 \u4f7f\u7528\u4e0e\u7b7e\u540d\u6d41\u7a0b<\/h3>\n<p>\u5728\u7f51\u9875\u4e2d\u4f7f\u7528 JS-SDK \u7684\u5168\u94fe\u8def\u6d41\u7a0b\u5982\u4e0b\uff1a<\/p>\n<ol>\n<li><strong>\u670d\u52a1\u7aef\u83b7\u53d6 access_token<\/strong>\uff1a\u4f7f\u7528 <code>corpid<\/code> \u548c <code>corpsecret<\/code> \u8c03\u7528 <code>GET https:\/\/qyapi.weixin.qq.com\/cgi-bin\/gettoken<\/code> \u83b7\u53d6 <code>access_token<\/code>\u3002<\/li>\n<li><strong>\u670d\u52a1\u7aef\u83b7\u53d6 jsapi_ticket \u5e76\u751f\u6210\u7b7e\u540d<\/strong>\uff1a\n<ul>\n<li>\u5982\u9700\u8c03\u7528<strong>\u4f01\u4e1a\u7ea7\u522b<\/strong>\u7684 JS-SDK \u63a5\u53e3\uff0c\u4f7f\u7528 <code>access_token<\/code> \u8c03\u7528 <code>GET https:\/\/qyapi.weixin.qq.com\/cgi-bin\/get_jsapi_ticket?access_token=ACCESS_TOKEN<\/code> \u83b7\u53d6\u4f01\u4e1a <code>jsapi_ticket<\/code>\u3002<\/li>\n<li>\u5982\u8fd8\u9700\u8c03\u7528<strong>\u5e94\u7528\u7ea7\u522b<\/strong>\u7684\u63a5\u53e3\uff08\u5982 <code>agentConfig<\/code>\uff09\uff0c\u5219\u989d\u5916\u8c03\u7528 <code>GET https:\/\/qyapi.weixin.qq.com\/cgi-bin\/ticket\/get?access_token=ACCESS_TOKEN&amp;type=agent_config<\/code> \u83b7\u53d6\u5e94\u7528 <code>jsapi_ticket<\/code>\u3002<\/li>\n<li>\u670d\u52a1\u7aef\u4f7f\u7528\u83b7\u53d6\u5230\u7684 <code>jsapi_ticket<\/code>\u3001<code>nonceStr<\/code>\uff08\u968f\u673a\u5b57\u7b26\u4e32\uff09\u3001<code>timestamp<\/code>\uff08\u65f6\u95f4\u6233\uff09\u4ee5\u53ca\u5f53\u524d\u9875\u9762 <code>url<\/code> \u6309\u89c4\u5219\u62fc\u63a5\u540e\u8fdb\u884c SHA1 \u7b7e\u540d\uff0c\u5f97\u5230 <code>signature<\/code>\u3002<\/li>\n<\/ul>\n<\/li>\n<li><strong>\u524d\u7aef\u9875\u9762\u5f15\u5165\u5e76\u914d\u7f6e<\/strong>\uff1a\n<ul>\n<li>\u5f15\u5165\u4f01\u4e1a\u5fae\u4fe1\u7684 JS-SDK \u6587\u4ef6\u3002<\/li>\n<li>\u8c03\u7528 <code>wx.config<\/code> \u8fdb\u884c<strong>\u4f01\u4e1a\u7ea7<\/strong>\u914d\u7f6e\uff0c\u5176\u4e2d <code>signature<\/code> \u4f7f\u7528<strong>\u4f01\u4e1a jsapi_ticket<\/strong> \u751f\u6210\u7684\u7b7e\u540d\u3002<\/li>\n<li>\u5982\u9700\u4f7f\u7528\u5e94\u7528\u79c1\u6709\u80fd\u529b\uff0c\u5728 <code>wx.config<\/code> \u7684 <code>success<\/code> \u56de\u8c03\u4e2d\u7ee7\u7eed\u8c03\u7528 <code>wx.agentConfig<\/code>\uff0c\u5176 <code>signature<\/code> \u9700\u4f7f\u7528<strong>\u5e94\u7528 jsapi_ticket<\/strong> \u751f\u6210\u7684\u7b7e\u540d\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p><strong>\u7b80\u5355\u603b\u7ed3<\/strong>\uff1a<\/p>\n<ul>\n<li>\u63a5\u53e3\u4e00\uff08<code>\/get_jsapi_ticket<\/code>\uff09\u83b7\u53d6\u7684 ticket \u2192 \u7528\u4e8e<strong>\u6574\u4e2a\u4f01\u4e1a\u7ef4\u5ea6<\/strong>\u7684 JS-SDK \u9274\u6743\uff08<code>wx.config<\/code>\uff09\u3002<\/li>\n<li>\u63a5\u53e3\u4e8c\uff08<code>\/ticket\/get?type=agent_config<\/code>\uff09\u83b7\u53d6\u7684 ticket \u2192 \u7528\u4e8e<strong>\u7279\u5b9a\u5e94\u7528\u7ef4\u5ea6<\/strong>\u7684\u9274\u6743\uff08<code>wx.agentConfig<\/code>\uff09\u3002<\/li>\n<\/ul>\n<h3>2.3 \u5e38\u89c1\u95ee\u9898\u4e0e\u6ce8\u610f\u4e8b\u9879<\/h3>\n<ul>\n<li><strong>IP \u767d\u540d\u5355<\/strong>\uff1a\u83b7\u53d6 <code>jsapi_ticket<\/code> \u65f6\u4f1a\u6821\u9a8c IP\uff0c\u8bf7\u786e\u4fdd\u670d\u52a1\u5668 IP \u5df2\u52a0\u5165\u4f01\u4e1a\u5fae\u4fe1\u5e94\u7528\u8be6\u60c5\u4e2d\u7684&#8221;\u4f01\u4e1a\u53ef\u4fe1 IP&#8221;\u5217\u8868\u3002<\/li>\n<li><strong>\u65f6\u6548\u4e0e\u7f13\u5b58<\/strong>\uff1a<code>jsapi_ticket<\/code> \u7684\u6709\u6548\u671f\u4e3a <strong>7200 \u79d2<\/strong>\uff0c\u540c\u6837\u9700\u8981\u670d\u52a1\u7aef\u7f13\u5b58\u5e76\u5b9a\u65f6\u5237\u65b0\uff0c\u907f\u514d\u89e6\u53d1\u9891\u7387\u9650\u5236\u3002<\/li>\n<li><strong>\u7b7e\u540d\u7b97\u6cd5<\/strong>\uff1a\u7b7e\u540d\u7b97\u6cd5\u4e0e\u516c\u4f17\u53f7\u7c7b\u4f3c\uff0c\u4f46\u52a1\u5fc5\u4f7f\u7528\u4f01\u4e1a\u5fae\u4fe1\u8981\u6c42\u7684\u53c2\u6570\u987a\u5e8f\u548c\u5f53\u524d\u9875\u9762\u7684\u5b8c\u6574 URL\uff08\u4e0d\u5305\u542b <code>#<\/code> \u53ca\u5176\u540e\u9762\u90e8\u5206\uff09\u3002<\/li>\n<\/ul>\n<h2>\u4e09\u3001\u4ee3\u7801\u6539\u9020\u5b9e\u8df5\uff1a\u4ece\u516c\u4f17\u53f7\u8fc1\u79fb\u5230\u4f01\u4e1a\u5fae\u4fe1<\/h2>\n<p>\u4ee5\u4e0b\u793a\u4f8b\u5c55\u793a\u5982\u4f55\u5c06\u4e00\u6bb5\u57fa\u4e8e\u5fae\u4fe1\u516c\u4f17\u53f7\u7684 <code>access_token<\/code> \u4e0e <code>jsapi_ticket<\/code> \u83b7\u53d6\u903b\u8f91\u6539\u9020\u4e3a\u4f01\u4e1a\u5fae\u4fe1\u7248\u672c\u3002\u6539\u9020\u6d89\u53ca\u4e09\u4e2a\u6838\u5fc3\u90e8\u5206\uff1a<strong>API \u5730\u5740<\/strong>\u3001<strong>\u53c2\u6570\u540d\u79f0<\/strong>\uff08<code>appid<\/code>\u2192<code>corpid<\/code>\uff0c<code>secret<\/code>\u2192<code>corpsecret<\/code>\uff09\u4ee5\u53ca <strong>ticket \u7c7b\u578b\u83b7\u53d6\u65b9\u5f0f<\/strong>\uff08\u4f01\u4e1a\u5fae\u4fe1\u6709\u4e24\u79cd ticket\uff09\u3002<\/p>\n<h3>3.1 \u4fee\u6539\u914d\u7f6e\u5e38\u91cf\uff08WxWorkApiUrl\uff09<\/h3>\n<pre><code>public static final String API_QY_HOST_URL = \"https:\/\/qyapi.weixin.qq.com\";\n\n\/\/ \u83b7\u53d6\u4f01\u4e1a\u5fae\u4fe1 access_token\uff08\u6ce8\u610f\u53c2\u6570\u540d\u4e0d\u540c\uff09\npublic static final String GET_ACCESS_TOKEN_URL = API_QY_HOST_URL + \"\/cgi-bin\/gettoken?corpid=%s&amp;corpsecret=%s\";\n\n\/\/ \u83b7\u53d6\u4f01\u4e1a\u7ea7 jsapi_ticket\uff08\u7528\u4e8e wx.config\uff09\npublic static final String GET_JSAPI_TICKET_URL = API_QY_HOST_URL + \"\/cgi-bin\/get_jsapi_ticket?access_token=%s\";\n\n\/\/ \u83b7\u53d6\u5e94\u7528\u7ea7 jsapi_ticket\uff08\u7528\u4e8e wx.agentConfig\uff09\npublic static final String GET_AGENT_TICKET_URL = API_QY_HOST_URL + \"\/cgi-bin\/ticket\/get?access_token=%s&amp;type=agent_config\";<\/code><\/pre>\n<h3>3.2 \u4fee\u6539 getAccessToken \u65b9\u6cd5<\/h3>\n<p>\u4e3b\u8981\u53d8\u5316\uff1a\u53c2\u6570\u540d\u4ece <code>appid\/secret<\/code> \u6539\u4e3a <code>corpid\/corpsecret<\/code>\uff0cAPI \u5730\u5740\u76f8\u5e94\u6539\u53d8\u3002<\/p>\n<pre><code>private String getAccessToken(WxWorkProperties.WorkConfig workConfig, int retryTimes) {\n    \/\/ Redis key \u5efa\u8bae\u4e5f\u4fee\u6539\uff0c\u907f\u514d\u4e0e\u516c\u4f17\u53f7\u7f13\u5b58\u51b2\u7a81\n    if (redisService.hasKey(Constant.REDIS_WORK_ACCESS_TOKEN_KEY.concat(workConfig.getCorpId()))) {\n        return (String) redisService.get(Constant.REDIS_WORK_ACCESS_TOKEN_KEY.concat(workConfig.getCorpId()));\n    }\n\n    logger.info(\"\u8bf7\u6c42\u4f01\u4e1a\u5fae\u4fe1\u8bf7\u6c42\u53c2\u6570{}\", FastJsonUtils.toJson(workConfig));\n    String responseText = restTemplate.getForObject(\n        String.format(WxWorkApiUrl.GET_ACCESS_TOKEN_URL, workConfig.getCorpId(), workConfig.getCorpSecret()),\n        String.class\n    );\n    logger.info(\"\u8bf7\u6c42\u4f01\u4e1a\u5fae\u4fe1\u8fd4\u56de{}\", responseText);\n\n    JSONObject jsonObject = FastJsonUtils.toJSONObject(responseText);\n    \/\/ \u4f01\u4e1a\u5fae\u4fe1\u9519\u8bef\u7801\u5904\u7406\uff08\u4e0e\u516c\u4f17\u53f7\u7565\u6709\u4e0d\u540c\uff09\n    if (jsonObject.containsKey(\"errcode\") &amp;&amp; jsonObject.getInteger(\"errcode\") != 0) {\n        throw new RuntimeException(\"\u83b7\u53d6 access_token \u5931\u8d25\uff1a\" + jsonObject.getString(\"errmsg\"));\n    }\n\n    String accessToken = jsonObject.getString(\"access_token\");\n    redisService.set(\n        Constant.REDIS_WORK_ACCESS_TOKEN_KEY.concat(workConfig.getCorpId()),\n        accessToken,\n        jsonObject.getInteger(\"expires_in\") - 200\n    );\n    return accessToken;\n}<\/code><\/pre>\n<h3>3.3 \u4fee\u6539 getJsapiTicket \u65b9\u6cd5\uff08\u5173\u952e\u70b9\uff09<\/h3>\n<p>\u4f01\u4e1a\u5fae\u4fe1\u9700\u6839\u636e\u4f7f\u7528\u573a\u666f\u83b7\u53d6\u4e0d\u540c\u7684 ticket\uff0c\u8fd9\u91cc\u62c6\u5206\u4e3a\u4e24\u4e2a\u65b9\u6cd5\uff1a<\/p>\n<pre><code>\/**\n * \u83b7\u53d6\u4f01\u4e1a\u7ea7 jsapi_ticket\uff08\u7528\u4e8e wx.config \u521d\u59cb\u5316\uff09\n *\/\nprivate String getCorpJsapiTicket(String corpId, String accessToken) {\n    if (redisService.hasKey(Constant.REDIS_WORK_CORP_TICKET_KEY.concat(corpId))) {\n        return (String) redisService.get(Constant.REDIS_WORK_CORP_TICKET_KEY.concat(corpId));\n    }\n\n    logger.info(\"\u8bf7\u6c42\u4f01\u4e1a\u5fae\u4fe1\u4f01\u4e1a\u7ea7 ticket\uff0caccessToken:{}\", accessToken);\n    String responseContent = restTemplate.getForObject(\n        String.format(WxWorkApiUrl.GET_JSAPI_TICKET_URL, accessToken),\n        String.class\n    );\n    logger.info(\"\u8bf7\u6c42\u4f01\u4e1a\u5fae\u4fe1\u8fd4\u56de{}\", responseContent);\n\n    JSONObject jsonObject = FastJsonUtils.toJSONObject(responseContent);\n    if (jsonObject.getInteger(\"errcode\") != 0) {\n        throw new RuntimeException(\"\u83b7\u53d6\u4f01\u4e1a\u7ea7 ticket \u5931\u8d25\uff1a\" + jsonObject.getString(\"errmsg\"));\n    }\n\n    String jsapiTicket = jsonObject.getString(\"ticket\");\n    redisService.set(\n        Constant.REDIS_WORK_CORP_TICKET_KEY.concat(corpId),\n        jsapiTicket,\n        jsonObject.getInteger(\"expires_in\") - 200\n    );\n    return jsapiTicket;\n}\n\n\/**\n * \u83b7\u53d6\u5e94\u7528\u7ea7 jsapi_ticket\uff08\u7528\u4e8e wx.agentConfig\uff09\n *\/\nprivate String getAgentJsapiTicket(String corpId, String accessToken) {\n    if (redisService.hasKey(Constant.REDIS_WORK_AGENT_TICKET_KEY.concat(corpId))) {\n        return (String) redisService.get(Constant.REDIS_WORK_AGENT_TICKET_KEY.concat(corpId));\n    }\n\n    logger.info(\"\u8bf7\u6c42\u4f01\u4e1a\u5fae\u4fe1\u5e94\u7528\u7ea7 ticket\uff0caccessToken:{}\", accessToken);\n    String responseContent = restTemplate.getForObject(\n        String.format(WxWorkApiUrl.GET_AGENT_TICKET_URL, accessToken),\n        String.class\n    );\n    logger.info(\"\u8bf7\u6c42\u4f01\u4e1a\u5fae\u4fe1\u8fd4\u56de{}\", responseContent);\n\n    JSONObject jsonObject = FastJsonUtils.toJSONObject(responseContent);\n    if (jsonObject.getInteger(\"errcode\") != 0) {\n        throw new RuntimeException(\"\u83b7\u53d6\u5e94\u7528\u7ea7 ticket \u5931\u8d25\uff1a\" + jsonObject.getString(\"errmsg\"));\n    }\n\n    String jsapiTicket = jsonObject.getString(\"ticket\");\n    redisService.set(\n        Constant.REDIS_WORK_AGENT_TICKET_KEY.concat(corpId),\n        jsapiTicket,\n        jsonObject.getInteger(\"expires_in\") - 200\n    );\n    return jsapiTicket;\n}<\/code><\/pre>\n<h3>3.4 \u4fee\u6539\u7b7e\u540d\u751f\u6210\u903b\u8f91\uff08\u9002\u914d\u53cc ticket\uff09<\/h3>\n<p>\u4f01\u4e1a\u5fae\u4fe1\u524d\u7aef\u9700\u8981\u4e24\u6b21\u914d\u7f6e\uff08<code>wx.config<\/code> \u548c <code>wx.agentConfig<\/code>\uff09\uff0c\u56e0\u6b64\u670d\u52a1\u7aef\u9700\u751f\u6210<strong>\u4e24\u4e2a\u7b7e\u540d<\/strong>\uff1a<\/p>\n<pre><code>public WxWorkJsapiSignature getSignatures(String url, String corpId, String agentId) {\n    \/\/ 1. \u83b7\u53d6 access_token\n    String accessToken = getAccessToken(corpId, corpSecret);\n\n    \/\/ 2. \u83b7\u53d6\u4f01\u4e1a\u7ea7 ticket\uff08\u7528\u4e8e wx.config\uff09\n    String corpTicket = getCorpJsapiTicket(corpId, accessToken);\n    long timestamp = System.currentTimeMillis() \/ 1000;\n    String nonceStr = StringUtils.getRandomStr(16);\n\n    \/\/ 3. \u751f\u6210 wx.config \u7684\u7b7e\u540d\n    String corpSignature = SHA1.genWithAmple(\n        \"jsapi_ticket=\" + corpTicket,\n        \"noncestr=\" + nonceStr,\n        \"timestamp=\" + timestamp,\n        \"url=\" + url\n    );\n\n    \/\/ 4. \u83b7\u53d6\u5e94\u7528\u7ea7 ticket\uff08\u7528\u4e8e wx.agentConfig\uff09\n    String agentTicket = getAgentJsapiTicket(corpId, accessToken);\n    String agentSignature = SHA1.genWithAmple(\n        \"jsapi_ticket=\" + agentTicket,\n        \"noncestr=\" + nonceStr,\n        \"timestamp=\" + timestamp,\n        \"url=\" + url\n    );\n\n    \/\/ 5. \u8fd4\u56de\u53cc\u7b7e\u540d\u7ed3\u679c\n    WxWorkJsapiSignature signature = new WxWorkJsapiSignature();\n    signature.setCorpId(corpId);\n    signature.setAgentId(agentId);  \/\/ \u4f01\u4e1a\u5fae\u4fe1\u9700\u8981\u4f20\u9012 agentId\n    signature.setNonceStr(nonceStr);\n    signature.setTimestamp(timestamp);\n    signature.setCorpSignature(corpSignature);   \/\/ \u7528\u4e8e wx.config\n    signature.setAgentSignature(agentSignature); \/\/ \u7528\u4e8e wx.agentConfig\n\n    return signature;\n}<\/code><\/pre>\n<h3>3.5 \u524d\u7aef JS-SDK \u8c03\u7528\u793a\u4f8b<\/h3>\n<p>\u524d\u7aef\u6536\u5230\u53cc\u7b7e\u540d\u540e\uff0c\u9700\u4f9d\u6b21\u8c03\u7528 <code>wx.config<\/code> \u4e0e <code>wx.agentConfig<\/code>\uff1a<\/p>\n<pre><code>wx.config({\n    beta: true,\n    debug: true,\n    appId: '{{corpId}}',      \/\/ \u4f01\u4e1a\u5fae\u4fe1\u7684 corpid\n    timestamp: '{{timestamp}}',\n    nonceStr: '{{nonceStr}}',\n    signature: '{{corpSignature}}',  \/\/ \u4f7f\u7528\u4f01\u4e1a\u7ea7\u7b7e\u540d\n    jsApiList: ['chooseImage', 'openEnterpriseChat']\n});\n\nwx.ready(function() {\n    \/\/ config \u9a8c\u8bc1\u6210\u529f\u540e\uff0c\u518d\u8fdb\u884c agentConfig\n    wx.agentConfig({\n        corpid: '{{corpId}}',\n        agentid: '{{agentId}}',\n        timestamp: '{{timestamp}}',\n        nonceStr: '{{nonceStr}}',\n        signature: '{{agentSignature}}',  \/\/ \u4f7f\u7528\u5e94\u7528\u7ea7\u7b7e\u540d\n        jsApiList: ['sendChatMessage'],\n        success: function(res) {\n            console.log('agentConfig \u6210\u529f');\n        }\n    });\n});<\/code><\/pre>\n<h2>\u56db\u3001\u5173\u952e\u6ce8\u610f\u4e8b\u9879<\/h2>\n<ol>\n<li><strong>\u53c2\u6570\u540d\u79f0\u53d8\u5316<\/strong>\uff1a\u4f01\u4e1a\u5fae\u4fe1\u4f7f\u7528 <code>corpid<\/code> \u548c <code>corpsecret<\/code>\uff0c\u800c\u975e\u516c\u4f17\u53f7\u7684 <code>appid<\/code>\/<code>secret<\/code>\u3002<\/li>\n<li><strong>API \u5730\u5740\u4e0d\u540c<\/strong>\uff1a\u57df\u540d\u4ece <code>api.weixin.qq.com<\/code> \u6539\u4e3a <code>qyapi.weixin.qq.com<\/code>\u3002<\/li>\n<li><strong>\u53cc ticket \u673a\u5236<\/strong>\uff1a\u5fc5\u987b\u540c\u65f6\u5b9e\u73b0\u4e24\u79cd ticket \u7684\u83b7\u53d6\uff0c\u524d\u7aef\u624d\u80fd\u5b8c\u6574\u4f7f\u7528 JS-SDK\u3002<\/li>\n<li><strong>\u9519\u8bef\u7801\u5904\u7406<\/strong>\uff1a\u4f01\u4e1a\u5fae\u4fe1\u6210\u529f\u65f6\u8fd4\u56de <code>errcode=0<\/code>\uff0c\u516c\u4f17\u53f7\u5219\u662f\u76f4\u63a5\u8fd4\u56de\u6570\u636e\u3002<\/li>\n<li><strong>Redis \u9694\u79bb<\/strong>\uff1a\u5efa\u8bae\u4f7f\u7528\u4e0d\u540c\u7684\u7f13\u5b58 Key \u524d\u7f00\uff0c\u907f\u514d\u4e0e\u516c\u4f17\u53f7\u6570\u636e\u51b2\u7a81\u3002<\/li>\n<li><strong>IP \u767d\u540d\u5355<\/strong>\uff1a\u786e\u4fdd\u670d\u52a1\u5668 IP \u5df2\u6dfb\u52a0\u5230\u4f01\u4e1a\u5fae\u4fe1\u5e94\u7528\u7684&#8221;\u4f01\u4e1a\u53ef\u4fe1 IP&#8221;\u4e2d\u3002<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>\u524d\u8a00 \u5728\u65e5\u5e38\u5f00\u53d1\u4e2d\uff0c\u8bb8\u591a\u5f00\u53d1\u8005\u4f1a\u6df7\u6dc6\u5fae\u4fe1\u516c\u4f17\u53f7\u4e0e\u4f01\u4e1a\u5fae\u4fe1\u7684\u63a5\u53e3\u4f53\u7cfb\u3002\u5b9e\u9645\u4e0a\uff0c\u8fd9\u4e24\u4e2a\u5e73\u53f0\u662f\u5b8c\u5168\u72ec\u7acb\u7684\u4e24\u5957\u7cfb\u7edf\uff0c\u4e0d [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-300","post","type-post","status-publish","format-standard","hentry","category-default"],"_links":{"self":[{"href":"https:\/\/wp.buildyou.top\/index.php\/wp-json\/wp\/v2\/posts\/300","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wp.buildyou.top\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wp.buildyou.top\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wp.buildyou.top\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wp.buildyou.top\/index.php\/wp-json\/wp\/v2\/comments?post=300"}],"version-history":[{"count":1,"href":"https:\/\/wp.buildyou.top\/index.php\/wp-json\/wp\/v2\/posts\/300\/revisions"}],"predecessor-version":[{"id":301,"href":"https:\/\/wp.buildyou.top\/index.php\/wp-json\/wp\/v2\/posts\/300\/revisions\/301"}],"wp:attachment":[{"href":"https:\/\/wp.buildyou.top\/index.php\/wp-json\/wp\/v2\/media?parent=300"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wp.buildyou.top\/index.php\/wp-json\/wp\/v2\/categories?post=300"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wp.buildyou.top\/index.php\/wp-json\/wp\/v2\/tags?post=300"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}