-
Notifications
You must be signed in to change notification settings - Fork 0
/
search.xml
224 lines (107 loc) · 232 KB
/
search.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
<?xml version="1.0" encoding="utf-8"?>
<search>
<entry>
<title>工作笔记</title>
<link href="/2024/01/30/gong-zuo-bi-ji/"/>
<url>/2024/01/30/gong-zuo-bi-ji/</url>
<content type="html"><![CDATA[<h1 id="技术笔记"><a href="#技术笔记" class="headerlink" title="技术笔记"></a>技术笔记</h1><h2 id="sql相关"><a href="#sql相关" class="headerlink" title="sql相关"></a>sql相关</h2><ol><li><p>查询一个数据库里面所有表的数据量</p><pre class="line-numbers language-sql" data-language="sql"><code class="language-sql"><span class="token keyword">ANALYZE</span> VERBOSE<span class="token punctuation">;</span><span class="token keyword">SELECT</span> nspname <span class="token keyword">AS</span> schemaname<span class="token punctuation">,</span> relname <span class="token keyword">AS</span> tablename<span class="token punctuation">,</span> reltuples::<span class="token keyword">bigint</span> <span class="token keyword">AS</span> row_count<span class="token keyword">FROM</span> pg_class<span class="token keyword">JOIN</span> pg_namespace <span class="token keyword">ON</span> pg_class<span class="token punctuation">.</span>relnamespace <span class="token operator">=</span> pg_namespace<span class="token punctuation">.</span>oid<span class="token keyword">WHERE</span> nspname <span class="token operator">=</span> <span class="token string">'public'</span> <span class="token operator">AND</span> relkind <span class="token operator">=</span> <span class="token string">'r'</span><span class="token punctuation">;</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre></li><li><p>更新邮箱字段</p><pre class="line-numbers language-sql" data-language="sql"><code class="language-sql"><span class="token keyword">UPDATE</span> <span class="token keyword">public</span><span class="token punctuation">.</span>users<span class="token keyword">SET</span> email<span class="token operator">=</span><span class="token keyword">REPLACE</span><span class="token punctuation">(</span>email<span class="token punctuation">,</span><span class="token string">'@daimler.com'</span><span class="token punctuation">,</span><span class="token string">'@mercedes-benz.com'</span><span class="token punctuation">)</span><span class="token keyword">WHERE</span> email <span class="token operator">like</span> <span class="token string">'%@daimler.com%'</span> <span class="token operator">or</span> email <span class="token operator">like</span> ‘<span class="token operator">%</span><span class="token variable">@Daimler.com</span><span class="token operator">%</span><span class="token string">' ;UPDATE public.sc AS ltSET profile = REPLACE(profile::text,'</span><span class="token variable">@daimler.com</span>'<span class="token punctuation">,</span><span class="token string">'@mercedes-benz.com'</span><span class="token punctuation">)</span>::jsonb<span class="token keyword">WHERE</span> <span class="token punctuation">(</span>profile<span class="token operator">-</span><span class="token operator">>></span><span class="token string">'email'</span><span class="token punctuation">)</span> <span class="token operator">like</span> <span class="token string">'%@daimler.com%'</span><span class="token punctuation">;</span><span class="token keyword">update</span> companys <span class="token keyword">set</span> name <span class="token operator">=</span> name <span class="token operator">||</span> hstore<span class="token punctuation">(</span><span class="token string">'en'</span><span class="token punctuation">,</span> <span class="token keyword">REPLACE</span><span class="token punctuation">(</span>name<span class="token operator">-</span><span class="token operator">></span><span class="token string">'en'</span><span class="token punctuation">,</span><span class="token string">'Daimler'</span><span class="token punctuation">,</span><span class="token string">'Mercedes'</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token keyword">where</span> name<span class="token operator">-</span><span class="token operator">></span><span class="token string">'en'</span> <span class="token operator">like</span> <span class="token string">'%Daimler%'</span><span class="token punctuation">;</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre></li><li><p>postgres导入数据命令</p><pre class="line-numbers language-sql" data-language="sql"><code class="language-sql">export PATH<span class="token operator">=</span><span class="token string">"/Applications/Postgres.app/Contents/Versions/9.6/bin:$PATH"</span>psql <span class="token operator">-</span>d sap <span class="token operator">-</span>U postgres <span class="token operator">-</span>f <span class="token operator">/</span>Users<span class="token operator">/</span>Desktop<span class="token operator">/</span>sap<span class="token punctuation">.</span><span class="token keyword">sql</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span></span></code></pre></li></ol><h2 id="Python相关"><a href="#Python相关" class="headerlink" title="Python相关"></a>Python相关</h2><ol><li><p>项目启动时安装包命令<br><code>pip install -r requirements/dev.txt -i https://pypi.tuna.tsinghua.edu.cn/simple</code></p></li><li><p>将一个数组中的值添加到另一个数组<br><code>extend()</code></p></li></ol><h2 id="Docker"><a href="#Docker" class="headerlink" title="Docker"></a>Docker</h2><ol><li><p>查看日志<br><code>docker logs -f -t --tail 10 content_name</code></p></li><li><p>查看所有服务<br><code>docker ps -a</code></p></li><li><p>进入docker容器<br><code>docker exec -it content_name bash</code></p></li><li><p>数据库操作</p><pre class="line-numbers language-none"><code class="language-none">psql -U postgres\q quite DBexit<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span></span></code></pre></li><li><p>redis操作</p><pre class="line-numbers language-none"><code class="language-none">redis-cliauth passwordselect 10del key (清理redis的key)keys *(列出所有的key)<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span></span></code></pre></li></ol><p><em>FLUSHDB就是清除当前DB里的所有数据(慎用)FLUSHALL就是清除所有的DB里的所有数据(不要用)</em></p><h2 id="Git"><a href="#Git" class="headerlink" title="Git"></a>Git</h2><ol><li><p>手动merge<br>git merge –no-commit –no-ff other_branch</p></li><li><p><a href="https://zhuanlan.zhihu.com/p/465078705">代码迁移参考</a></p></li></ol>]]></content>
<categories>
<category> 技术文档 </category>
</categories>
<tags>
<tag> python </tag>
<tag> 上云 </tag>
</tags>
</entry>
<entry>
<title>Python培训</title>
<link href="/2022/06/30/python-pei-xun/"/>
<url>/2022/06/30/python-pei-xun/</url>
<content type="html"><![CDATA[<h1 id="python培训"><a href="#python培训" class="headerlink" title="python培训"></a>python培训</h1><h2 id="学习思想"><a href="#学习思想" class="headerlink" title="学习思想"></a>学习思想</h2><p>学习20%的关键技术解决80%的问题</p><p>90%,60%,30%(重要的原则)</p><p>学习,模仿,<code>创新</code></p><p>敏捷开发</p><p>学会找组件,避免重复造轮子</p><p>业务场景的思考方法,从业务场景中提取业务需求,技术需求</p><h2 id="安装环境"><a href="#安装环境" class="headerlink" title="安装环境"></a>安装环境</h2><ul><li>python3.6.8</li><li>nodejs 14.x</li><li>VScode</li><li>MariaDB</li><li>Navicat Premium 15</li></ul><h2 id="python历史"><a href="#python历史" class="headerlink" title="python历史"></a>python历史</h2><p>解释型、面向对象、动态数据类型的高级程序设计语言</p><h2 id="主要技术场景"><a href="#主要技术场景" class="headerlink" title="主要技术场景"></a>主要技术场景</h2><ul><li>人工智能 机器学习(sklearn)+深度学习(tensorflow2,paddlepaddle)</li><li>自动化运维 psutil</li><li>金融量化以及金融量化框架等 tushare</li><li>数据分析领域</li><li>大数据领域spark</li><li>爬虫 selenium</li></ul><h2 id="业务产品"><a href="#业务产品" class="headerlink" title="业务产品"></a>业务产品</h2><p>大数据数据应用</p><ul><li>用户挖掘</li><li>流量使用情况</li><li><code>运维驾驶舱</code></li></ul><h2 id="基本语法学习"><a href="#基本语法学习" class="headerlink" title="基本语法学习"></a>基本语法学习</h2><ul><li><p>变量</p></li><li><p>面向过程</p><p>顺序,选择,循环</p></li><li><p>面向对象</p></li></ul><h2 id="SQL"><a href="#SQL" class="headerlink" title="SQL"></a>SQL</h2><p>MariaDB</p><p>修改4个地方,my.ini文件 端口和characters</p><p>进入bin文件夹,双击mysqld.exe</p><h2 id="回归,分类,聚类"><a href="#回归,分类,聚类" class="headerlink" title="回归,分类,聚类"></a>回归,分类,聚类</h2><p>回归:有监督学习的两大应用之一,产生连续的结果。</p><blockquote><p>例如向<strong>模型</strong>输入人的各种数据的训练样本,产生“输入一个人的数据,判断此人20年后今后的经济能力”的结果,结果是连续的,往往得到一条回归曲线。当输入自变量不同时,输出的因变量非离散分布(不仅仅是一条线性直线,多项曲线也是回归曲线)。</p></blockquote><p>分类:有监督学习的两大应用之一,产生离散的结果。</p><blockquote><p>例如向<strong>模型</strong>输入人的各种数据的训练样本,产生“输入一个人的数据,判断是否患有癌症”的结果,结果必定是离散的,只有<strong>“是”或“否”。(即有目标和标签,能判断目标特征是属于哪一个类型)</strong></p></blockquote><p>聚类:无监督学习的结果。聚类的结果将产生一组集合,集合中的对象与同集合中的对象彼此相似,与其他集合中的对象<strong>相异</strong>。</p><blockquote><p>没有标准参考的学生给书本分的类别,表示自己认为这些书可能是同一类别的(具体什么类别不知道,没有标签和目标,即不是判断书的好坏(目标,标签),只能凭借特征而分类)。</p></blockquote>]]></content>
<tags>
<tag> Python </tag>
</tags>
</entry>
<entry>
<title>flask 小白白</title>
<link href="/2022/03/27/flask-xiao-bai-bai/"/>
<url>/2022/03/27/flask-xiao-bai-bai/</url>
<content type="html"><![CDATA[<h2 id="flask项目启动命令"><a href="#flask项目启动命令" class="headerlink" title="flask项目启动命令"></a>flask项目启动命令</h2><pre class="line-numbers language-none"><code class="language-none">export FLASK_APP=./autoapp.py export FLASK_DEBUG=1flask run --host 0.0.0.0 --port 5000<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span></span></code></pre><h2 id="flask数据生成命令"><a href="#flask数据生成命令" class="headerlink" title="flask数据生成命令"></a>flask数据生成命令</h2><pre class="line-numbers language-none"><code class="language-none">flask db initflask db migrateflask db upgrade<span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span></span></code></pre>]]></content>
<tags>
<tag> python </tag>
</tags>
</entry>
<entry>
<title>前端大杂烩</title>
<link href="/2021/07/29/qian-duan-da-za-hui/"/>
<url>/2021/07/29/qian-duan-da-za-hui/</url>
<content type="html"><![CDATA[<h1 id="前端大杂烩"><a href="#前端大杂烩" class="headerlink" title="前端大杂烩"></a>前端大杂烩</h1><ol><li><h3 id="如何判断数据类型"><a href="#如何判断数据类型" class="headerlink" title="如何判断数据类型"></a><strong>如何判断数据类型</strong></h3><ul><li>typeof,返回值格式为字符串类型</li><li>判断已知对象类型的方法: instanceof,instanceof 后面一定要是对象类型,并且大小写不能错</li><li>根据对象的 constructor 判断,alert(c.constructor === Array) ———-> true</li><li>通用但很繁琐的方法: prototype,alert(Object.prototype.toString.call(a) === ‘[object String]’) ——-> true;</li><li>无敌万能的方法:jquery.type()</li></ul></li><li><h3 id="js-浏览器事件循环机制"><a href="#js-浏览器事件循环机制" class="headerlink" title="js 浏览器事件循环机制"></a><strong>js 浏览器事件循环机制</strong></h3><ul><li><p><strong>浏览器执行线程</strong></p><p>浏览器是多进程的,浏览器每一个 tab 标签都代表一个独立的进程,其中浏览器渲染进程(浏览器内核)属于浏览器多进程中的一种,主要负责页面渲染,脚本执行,事件处理等<br>其包含的线程有:GUI 渲染线程(负责渲染页面,解析 HTML,CSS 构成 DOM 树)、JS 引擎线程、事件触发线程、定时器触发线程、http 请求线程等主要线程</p></li><li><p><strong>关于执行中的线程</strong></p><p><strong>主线程</strong>:也就是 js 引擎执行的线程,这个线程只有一个,页面渲染、函数处理都在这个主线程上执行。<br><strong>工作线程</strong>:也称幕后线程,这个线程可能存在于浏览器或 js 引擎内,与主线程是分开的,处理文件读取、网络请求等异步事件。</p><p>**任务队列( Event Queue )**:所有的任务可以分为同步任务和异步任务,同步任务,顾名思义,就是立即执行的任务,同步任务一般会直接进入到主线程中执行;而异步任务,就是异步执行的任务,比如 ajax 网络请求,setTimeout 定时函数等都属于异步任务,异步任务会通过任务队列的机制(先进先出的机制)来进行协调。</p></li><li><p><strong>同步和异步任务分别进入不同的执行环境,同步的进入主线程,即主执行栈,异步的进入任务队列。主线程内的任务执行完毕为空,会去任务队列读取对应的任务,推入主线程执行。 上述过程的不断重复就是我们说的 Event Loop (事件循环)。</strong></p></li><li><p><strong>宏任务主要包含:script( 整体代码)、setTimeout、setInterval、I/O、UI 交互事件、setImmediate(Node.js 环境)</strong></p></li><li><p><strong>微任务主要包含:Promise、MutaionObserver、process.nextTick(Node.js 环境)</strong></p><p>例题</p></li></ul> <pre class="line-numbers language-none"><code class="language-none">console.log('test');<span aria-hidden="true" class="line-numbers-rows"><span></span></span></code></pre> <pre class="line-numbers language-javascript" data-language="javascript"><code class="language-javascript">console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token string">"script start"</span><span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token function">setTimeout</span><span class="token punctuation">(</span><span class="token keyword">function</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token string">"timeout1"</span><span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token number">10</span><span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token keyword">new</span> <span class="token class-name">Promise</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token parameter">resolve</span><span class="token punctuation">)</span> <span class="token operator">=></span> <span class="token punctuation">{</span> console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token string">"promise1"</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token function">resolve</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token function">setTimeout</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">=></span> console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token string">"timeout2"</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token number">10</span><span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">then</span><span class="token punctuation">(</span><span class="token keyword">function</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token string">"then1"</span><span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token string">"script end"</span><span class="token punctuation">)</span><span class="token punctuation">;</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre><p> 首先,事件循环从宏任务 (macrotask) 队列开始,最初始,宏任务队列中,只有一个 scrip t(整体代码)任务;当遇到任务源 (task source) 时,则会先分发任务到对应的任务队列中去。所以,就和上面例子类似,首先遇到了 console.log,输出 script start; 接着往下走,遇到 setTimeout 任务源,将其分发到任务队列中去,记为 timeout1; 接着遇到 promise,new promise 中的代码立即执行,输出 promise1, 然后执行 resolve ,遇到 setTimeout ,将其分发到任务队列中去,记为 timemout2, 将其 then 分发到微任务队列中去,记为 then1; 接着遇到 console.log 代码,直接输出 script end 接着检查微任务队列,发现有个 then1 微任务,执行,输出 then1 再检查微任务队列,发现已经清空,则开始检查宏任务队列,执行 timeout1,输出 timeout1; 接着执行 timeout2,输出 timeout2 至此,所有的都队列都已清空,执行完毕。其输出的顺序依次是:script start, promise1, script end, then1, timeout1, timeout2</p> <pre class="line-numbers language-javascript" data-language="javascript"><code class="language-javascript"><span class="token keyword">function</span> <span class="token function">test</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token string">"start"</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token function">setTimeout</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">=></span> <span class="token punctuation">{</span> console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token string">"children2"</span><span class="token punctuation">)</span><span class="token punctuation">;</span> Promise<span class="token punctuation">.</span><span class="token function">resolve</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">then</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">=></span> <span class="token punctuation">{</span> console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token string">"children2-1"</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token function">setTimeout</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">=></span> <span class="token punctuation">{</span> console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token string">"children3"</span><span class="token punctuation">)</span><span class="token punctuation">;</span> Promise<span class="token punctuation">.</span><span class="token function">resolve</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">then</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">=></span> <span class="token punctuation">{</span> console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token string">"children3-1"</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">)</span><span class="token punctuation">;</span> Promise<span class="token punctuation">.</span><span class="token function">resolve</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">then</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">=></span> <span class="token punctuation">{</span> console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token string">"children1"</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span> console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token string">"end"</span><span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token punctuation">}</span><span class="token function">test</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre><p> start,end,children1,children2,children2-1,children3,children3-1</p></li><li><h3 id="js-事件委托"><a href="#js-事件委托" class="headerlink" title="js 事件委托"></a><strong>js 事件委托</strong></h3><ul><li><p><strong>基本概念</strong></p><p>事件委托,通俗地来讲,就是把一个元素响应事件(click、keydown……)的函数委托到另一个元素;</p><p>举个例子,比如一个宿舍的同学同时快递到了,一种方法就是他们都傻傻地一个个去领取,还有一种方法就是把这件事情委托给宿舍长,让一个人出去拿好所有快递,然后再根据收件人一一分发给每个宿舍同学;</p><p>在这里,取快递就是一个事件,每个同学指的是需要响应事件的 DOM 元素,而出去统一领取快递的宿舍长就是代理的元素,所以真正绑定事件的是这个元素,按照收件人分发快递的过程就是在事件执行中,需要判断当前响应的事件应该匹配到被代理元素中的哪一个或者哪几个。</p></li><li><p><strong>委托的优点</strong></p><ol><li>减少内存消耗</li><li>动态绑定事件</li></ol></li></ul></li><li><h3 id="深复制和浅复制"><a href="#深复制和浅复制" class="headerlink" title="深复制和浅复制"></a><strong>深复制和浅复制</strong></h3><p><strong>引用数据类型–名存在栈内存中,值存在于堆内存中,但是栈内存会提供一个引用的地址指向堆内存中的值</strong></p><p>当 b=a 进行拷贝时,其实复制的是 a 的引用地址,而并非堆里面的值。而当我们<strong>a[0]=1</strong>时进行数组修改时,由于 a 与 b 指向的是同一个地址,所以自然 b 也受了影响,这就是所谓的浅拷贝了。</p><p><strong>实现简单的深拷贝</strong></p><pre class="line-numbers language-javascript" data-language="javascript"><code class="language-javascript"><span class="token keyword">function</span> <span class="token function">deepClone</span><span class="token punctuation">(</span><span class="token parameter">obj</span><span class="token punctuation">)</span><span class="token punctuation">{</span> <span class="token keyword">let</span> objClone <span class="token operator">=</span> Array<span class="token punctuation">.</span><span class="token function">isArray</span><span class="token punctuation">(</span>obj<span class="token punctuation">)</span><span class="token operator">?</span><span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token operator">:</span><span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">;</span> <span class="token keyword">if</span><span class="token punctuation">(</span>obj <span class="token operator">&&</span> <span class="token keyword">typeof</span> obj<span class="token operator">===</span><span class="token string">"object"</span><span class="token punctuation">)</span><span class="token punctuation">{</span> <span class="token keyword">for</span><span class="token punctuation">(</span>key <span class="token keyword">in</span> obj<span class="token punctuation">)</span><span class="token punctuation">{</span> <span class="token keyword">if</span><span class="token punctuation">(</span>obj<span class="token punctuation">.</span><span class="token function">hasOwnProperty</span><span class="token punctuation">(</span>key<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">{</span> <span class="token comment">//判断ojb子元素是否为对象,如果是,递归复制</span> <span class="token keyword">if</span><span class="token punctuation">(</span>obj<span class="token punctuation">[</span>key<span class="token punctuation">]</span><span class="token operator">&&</span><span class="token keyword">typeof</span> obj<span class="token punctuation">[</span>key<span class="token punctuation">]</span> <span class="token operator">===</span><span class="token string">"object"</span><span class="token punctuation">)</span><span class="token punctuation">{</span> objClone<span class="token punctuation">[</span>key<span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token function">deepClone</span><span class="token punctuation">(</span>obj<span class="token punctuation">[</span>key<span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token punctuation">}</span><span class="token keyword">else</span><span class="token punctuation">{</span> <span class="token comment">//如果不是,简单复制</span> objClone<span class="token punctuation">[</span>key<span class="token punctuation">]</span> <span class="token operator">=</span> obj<span class="token punctuation">[</span>key<span class="token punctuation">]</span><span class="token punctuation">;</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> <span class="token keyword">return</span> objClone<span class="token punctuation">;</span><span class="token punctuation">}</span><span class="token keyword">let</span> a<span class="token operator">=</span><span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">,</span><span class="token number">2</span><span class="token punctuation">,</span><span class="token number">3</span><span class="token punctuation">,</span><span class="token number">4</span><span class="token punctuation">]</span><span class="token punctuation">,</span><span class="token keyword">let</span> b<span class="token operator">=</span><span class="token function">deepClone</span><span class="token punctuation">(</span>a<span class="token punctuation">)</span><span class="token punctuation">;</span>a<span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span><span class="token operator">=</span><span class="token number">2</span><span class="token punctuation">;</span>console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>a<span class="token punctuation">,</span>b<span class="token punctuation">)</span><span class="token punctuation">;</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre><pre class="line-numbers language-javascript" data-language="javascript"><code class="language-javascript"><span class="token keyword">function</span> <span class="token function">deepClone</span><span class="token punctuation">(</span><span class="token parameter">obj</span><span class="token punctuation">)</span><span class="token punctuation">{</span> <span class="token keyword">let</span> _obj <span class="token operator">=</span> <span class="token constant">JSON</span><span class="token punctuation">.</span><span class="token function">stringify</span><span class="token punctuation">(</span>obj<span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token keyword">let</span> objClone <span class="token operator">=</span> <span class="token constant">JSON</span><span class="token punctuation">.</span><span class="token function">parse</span><span class="token punctuation">(</span>_obj<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token keyword">return</span> objClone<span class="token punctuation">}</span><span class="token keyword">let</span> a<span class="token operator">=</span><span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">,</span><span class="token number">1</span><span class="token punctuation">,</span><span class="token punctuation">[</span><span class="token number">2</span><span class="token punctuation">,</span><span class="token number">3</span><span class="token punctuation">]</span><span class="token punctuation">,</span><span class="token number">4</span><span class="token punctuation">]</span><span class="token punctuation">,</span><span class="token keyword">let</span> b<span class="token operator">=</span><span class="token function">deepClone</span><span class="token punctuation">(</span>a<span class="token punctuation">)</span><span class="token punctuation">;</span>a<span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span><span class="token operator">=</span><span class="token number">1</span><span class="token punctuation">;</span>a<span class="token punctuation">[</span><span class="token number">2</span><span class="token punctuation">]</span><span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span><span class="token operator">=</span><span class="token number">1</span><span class="token punctuation">;</span>console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>a<span class="token punctuation">,</span>b<span class="token punctuation">)</span><span class="token punctuation">;</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre><p><strong>除了上面两种方法之外,我们还可以借用 JQ 的 extend 方法。</strong></p><p><strong>*$*.extend( [deep ], target, object1 [, objectN ] )</strong></p><p><strong>deep</strong>表示是否深拷贝,为 true 为深拷贝,为 false,则为浅拷贝</p><p><strong>target</strong> <strong>Object</strong>类型 目标对象,其他对象的成员属性将被附加到该对象上。</p><p><strong>object1 objectN</strong>可选。 Object 类型 第一个以及第 N 个被合并的对象。</p></li><li><h3 id="let、var、const-的区别"><a href="#let、var、const-的区别" class="headerlink" title="let、var、const 的区别"></a><strong>let、var、const 的区别</strong></h3><ul><li><p><strong>var</strong></p><p>var 定义的变量可以修改,如果不初始化会输出 undefined,不会报错。var 声明全局变量,换句话理解就是,声明在 for 循环中的变量,跳出 for 循环同样可以使用。</p></li><li><p><strong>let</strong></p><p>同一个变量,不可在声明之前调用,必须先定义再使用,否则会报错,循环体中可以用 let。let 是块级作用域,函数内部使用 let 定义后,对函数外部无影响。并且 let 不能定义同名变量,否则会报错。</p><p><strong>注意:必须声明<code>'use strict';</code>后才能使用<code>let</code>声明变量</strong>否则浏览并不能显示结果</p></li><li><p><strong>const</strong></p><p>用于声明常量,也具有块级作用域 ,也可声明块级。const 定义的变量不可以修改,而且必须初始化。<strong>它和 let 一样,也不能重复定义同一个变量,const 一旦定义,无法修改.</strong></p></li></ul></li><li><h3 id="JS-中变量的存储方式"><a href="#JS-中变量的存储方式" class="headerlink" title="JS 中变量的存储方式"></a><strong>JS 中变量的存储方式</strong></h3><ul><li><strong>栈内存</strong><ul><li>基本数据类型的值直接在栈内存中存储;</li><li>值与值之间是独立存在的,修改一个变量不会影响其他变量;</li><li>当比较两个基本数据类型的值时,就是比较值;</li></ul></li><li><strong>堆内存</strong><ul><li>对象(引用数据类型)是保存到堆内存中的,每创建一个新的对象,就会在堆内存中开辟一个新的空间;</li><li>而变量保存的是对象的内存地址(对象的引用),如果两个变量保存的是同一个对象引用,当一个变量修改属性是,另一个也会受到影响;</li><li>当清空一个变量的值时,只是断开该变量与对象的联系,另一个对象并不受影响</li><li>当比较两个引用数据类型时,比较的是对象的内存地址;</li></ul></li></ul></li><li><h3 id="this-的指向,箭头函数中-this-的指向"><a href="#this-的指向,箭头函数中-this-的指向" class="headerlink" title="this 的指向,箭头函数中 this 的指向"></a><strong>this 的指向,箭头函数中 this 的指向</strong></h3><ul><li><p><strong>全局环境下</strong></p><pre class="line-numbers language-javascript" data-language="javascript"><code class="language-javascript">console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">.</span>document <span class="token operator">===</span> document<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// true</span><span class="token comment">// 在浏览器中,全局对象为 window 对象:</span>console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token keyword">this</span> <span class="token operator">===</span> window<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// true</span><span class="token keyword">this</span><span class="token punctuation">.</span>a <span class="token operator">=</span> <span class="token number">37</span><span class="token punctuation">;</span>console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>window<span class="token punctuation">.</span>a<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// 37</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre></li><li><p><strong>函数上下文调用</strong></p><p>函数直接调用</p><pre class="line-numbers language-javascript" data-language="javascript"><code class="language-javascript"><span class="token comment">//非严格模式下,this 默认指向全局对象window</span><span class="token keyword">function</span> <span class="token function">f1</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token keyword">return</span> <span class="token keyword">this</span><span class="token punctuation">;</span><span class="token punctuation">}</span><span class="token function">f1</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">===</span> window<span class="token punctuation">;</span> <span class="token comment">// true</span><span class="token comment">//而严格模式下, this为undefined</span><span class="token keyword">function</span> <span class="token function">f2</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token string">"use strict"</span><span class="token punctuation">;</span> <span class="token comment">// 这里是严格模式</span> <span class="token keyword">return</span> <span class="token keyword">this</span><span class="token punctuation">;</span><span class="token punctuation">}</span><span class="token function">f2</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">===</span> <span class="token keyword">undefined</span><span class="token punctuation">;</span> <span class="token comment">// true</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre><p>对象中的 this</p><pre class="line-numbers language-javascript" data-language="javascript"><code class="language-javascript"><span class="token comment">//1</span><span class="token keyword">var</span> o <span class="token operator">=</span> <span class="token punctuation">{</span> prop<span class="token operator">:</span> <span class="token number">37</span><span class="token punctuation">,</span> <span class="token function-variable function">f</span><span class="token operator">:</span> <span class="token keyword">function</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token keyword">return</span> <span class="token keyword">this</span><span class="token punctuation">.</span>prop<span class="token punctuation">;</span> <span class="token punctuation">}</span><span class="token punctuation">}</span><span class="token punctuation">;</span>console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>o<span class="token punctuation">.</span><span class="token function">f</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">//37</span><span class="token keyword">var</span> a <span class="token operator">=</span> o<span class="token punctuation">.</span>f<span class="token punctuation">;</span>console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token function">a</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token operator">:</span> <span class="token comment">//undefined</span><span class="token keyword">var</span> o <span class="token operator">=</span> <span class="token punctuation">{</span>prop<span class="token operator">:</span> <span class="token number">37</span><span class="token punctuation">}</span><span class="token punctuation">;</span><span class="token keyword">function</span> <span class="token function">independent</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token keyword">return</span> <span class="token keyword">this</span><span class="token punctuation">.</span>prop<span class="token punctuation">;</span><span class="token punctuation">}</span>o<span class="token punctuation">.</span>f <span class="token operator">=</span> independent<span class="token punctuation">;</span>console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>o<span class="token punctuation">.</span><span class="token function">f</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// logs 37</span><span class="token comment">//2</span>o<span class="token punctuation">.</span>b <span class="token operator">=</span> <span class="token punctuation">{</span> g<span class="token operator">:</span> independent<span class="token punctuation">,</span> prop<span class="token operator">:</span> <span class="token number">42</span><span class="token punctuation">}</span><span class="token punctuation">;</span>console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>o<span class="token punctuation">.</span>b<span class="token punctuation">.</span><span class="token function">g</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// logs 42</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre><p>原型链中 this</p><pre class="line-numbers language-javascript" data-language="javascript"><code class="language-javascript"><span class="token keyword">var</span> o <span class="token operator">=</span> <span class="token punctuation">{</span> <span class="token function-variable function">f</span><span class="token operator">:</span> <span class="token keyword">function</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token keyword">return</span> <span class="token keyword">this</span><span class="token punctuation">.</span>a <span class="token operator">+</span> <span class="token keyword">this</span><span class="token punctuation">.</span>b<span class="token punctuation">;</span> <span class="token punctuation">}</span><span class="token punctuation">,</span><span class="token punctuation">}</span><span class="token punctuation">;</span><span class="token keyword">var</span> p <span class="token operator">=</span> Object<span class="token punctuation">.</span><span class="token function">create</span><span class="token punctuation">(</span>o<span class="token punctuation">)</span><span class="token punctuation">;</span>p<span class="token punctuation">.</span>a <span class="token operator">=</span> <span class="token number">1</span><span class="token punctuation">;</span>p<span class="token punctuation">.</span>b <span class="token operator">=</span> <span class="token number">4</span><span class="token punctuation">;</span>console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>p<span class="token punctuation">.</span><span class="token function">f</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// 5</span><span class="token comment">//谁调用指向谁</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre><p>构造函数中 this</p><pre class="line-numbers language-javascript" data-language="javascript"><code class="language-javascript"><span class="token keyword">function</span> <span class="token constant">C</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token keyword">this</span><span class="token punctuation">.</span>a <span class="token operator">=</span> <span class="token number">37</span><span class="token punctuation">;</span><span class="token punctuation">}</span><span class="token keyword">var</span> o <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">C</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>o<span class="token punctuation">.</span>a<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// logs 37</span><span class="token keyword">function</span> <span class="token constant">C2</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token keyword">this</span><span class="token punctuation">.</span>a <span class="token operator">=</span> <span class="token number">37</span><span class="token punctuation">;</span> <span class="token keyword">return</span> <span class="token punctuation">{</span> a<span class="token operator">:</span> <span class="token number">38</span> <span class="token punctuation">}</span><span class="token punctuation">;</span><span class="token punctuation">}</span><span class="token keyword">var</span> b <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">C2</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>b<span class="token punctuation">.</span>a<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// logs 38</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre><p>call & apply</p><pre class="line-numbers language-javascript" data-language="javascript"><code class="language-javascript"><span class="token keyword">function</span> <span class="token function">add</span><span class="token punctuation">(</span><span class="token parameter">c<span class="token punctuation">,</span> d</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token keyword">return</span> <span class="token keyword">this</span><span class="token punctuation">.</span>a <span class="token operator">+</span> <span class="token keyword">this</span><span class="token punctuation">.</span>b <span class="token operator">+</span> c <span class="token operator">+</span> d<span class="token punctuation">;</span><span class="token punctuation">}</span><span class="token keyword">var</span> o <span class="token operator">=</span> <span class="token punctuation">{</span> a<span class="token operator">:</span> <span class="token number">1</span><span class="token punctuation">,</span> b<span class="token operator">:</span> <span class="token number">3</span> <span class="token punctuation">}</span><span class="token punctuation">;</span><span class="token function">add</span><span class="token punctuation">.</span><span class="token function">call</span><span class="token punctuation">(</span>o<span class="token punctuation">,</span> <span class="token number">5</span><span class="token punctuation">,</span> <span class="token number">7</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// 1 + 3 + 5 + 7 = 16</span><span class="token function">add</span><span class="token punctuation">.</span><span class="token function">apply</span><span class="token punctuation">(</span>o<span class="token punctuation">,</span> <span class="token punctuation">[</span><span class="token number">10</span><span class="token punctuation">,</span> <span class="token number">20</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// 1 + 3 + 10 + 20 = 34</span><span class="token keyword">function</span> <span class="token function">tt</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token punctuation">}</span><span class="token comment">// 返回对象见下图(图1)</span><span class="token function">tt</span><span class="token punctuation">.</span><span class="token function">call</span><span class="token punctuation">(</span><span class="token number">5</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// Number {[[PrimitiveValue]]: 5}</span><span class="token function">tt</span><span class="token punctuation">.</span><span class="token function">call</span><span class="token punctuation">(</span><span class="token string">"asd"</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// String {0: "a", 1: "s", 2: "d", length: 3, [[PrimitiveValue]]: "asd"}</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre><p>bind 方法</p><pre class="line-numbers language-javascript" data-language="javascript"><code class="language-javascript"><span class="token keyword">function</span> <span class="token function">f</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token keyword">return</span> <span class="token keyword">this</span><span class="token punctuation">.</span>a<span class="token punctuation">;</span><span class="token punctuation">}</span><span class="token keyword">var</span> g <span class="token operator">=</span> <span class="token function">f</span><span class="token punctuation">.</span><span class="token function">bind</span><span class="token punctuation">(</span><span class="token punctuation">{</span> a<span class="token operator">:</span> <span class="token string">"azerty"</span> <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token function">g</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// azerty</span><span class="token keyword">var</span> o <span class="token operator">=</span> <span class="token punctuation">{</span> a<span class="token operator">:</span> <span class="token number">37</span><span class="token punctuation">,</span> f<span class="token operator">:</span> f<span class="token punctuation">,</span> g<span class="token operator">:</span> g <span class="token punctuation">}</span><span class="token punctuation">;</span>console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>o<span class="token punctuation">.</span><span class="token function">f</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span> o<span class="token punctuation">.</span><span class="token function">g</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// 37, azerty</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre></li><li><p><strong>DOM 事件处理函数中的 this & 内联事件中的 this</strong></p><p>DOM 事件处理函数</p><pre class="line-numbers language-javascript" data-language="javascript"><code class="language-javascript"><span class="token comment">// 被调用时,将关联的元素变成蓝色</span><span class="token keyword">function</span> <span class="token function">bluify</span><span class="token punctuation">(</span><span class="token parameter">e</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token comment">//在控制台打印出所点击元素</span> console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">//阻止时间冒泡</span> e<span class="token punctuation">.</span><span class="token function">stopPropagation</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">//阻止元素的默认事件</span> e<span class="token punctuation">.</span><span class="token function">preventDefault</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token keyword">this</span><span class="token punctuation">.</span>style<span class="token punctuation">.</span>backgroundColor <span class="token operator">=</span> <span class="token string">"#A5D9F3"</span><span class="token punctuation">;</span><span class="token punctuation">}</span><span class="token comment">// 获取文档中的所有元素的列表</span><span class="token keyword">var</span> elements <span class="token operator">=</span> document<span class="token punctuation">.</span><span class="token function">getElementsByTagName</span><span class="token punctuation">(</span><span class="token string">"*"</span><span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token comment">// 将bluify作为元素的点击监听函数,当元素被点击时,就会变成蓝色</span><span class="token keyword">for</span> <span class="token punctuation">(</span><span class="token keyword">var</span> i <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span> i <span class="token operator"><</span> elements<span class="token punctuation">.</span>length<span class="token punctuation">;</span> i<span class="token operator">++</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> elements<span class="token punctuation">[</span>i<span class="token punctuation">]</span><span class="token punctuation">.</span><span class="token function">addEventListener</span><span class="token punctuation">(</span><span class="token string">"click"</span><span class="token punctuation">,</span> bluify<span class="token punctuation">,</span> <span class="token boolean">false</span><span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token punctuation">}</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre><p>内联事件</p><ol><li>当代码被内联处理函数调用时,它的 this 指向监听器所在的 DOM 元素</li><li>当代码被包括在函数内部执行时,其 this 指向等同于 ****函数直接调用****的情况,即在非严格模式指向全局对象 window, 在严格模式指向 undefined</li></ol></li><li><p><strong>setTimeout & setInterval</strong></p><pre class="line-numbers language-javascript" data-language="javascript"><code class="language-javascript"><span class="token comment">//默认情况下代码</span><span class="token keyword">function</span> <span class="token function">Person</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token keyword">this</span><span class="token punctuation">.</span>age <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span> <span class="token function">setTimeout</span><span class="token punctuation">(</span><span class="token keyword">function</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token number">3000</span><span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token punctuation">}</span><span class="token keyword">var</span> p <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Person</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token comment">//3秒后返回 window 对象</span><span class="token operator">===</span><span class="token operator">===</span><span class="token operator">===</span><span class="token operator">===</span><span class="token operator">===</span><span class="token operator">===</span><span class="token operator">===</span><span class="token operator">===</span><span class="token operator">===</span><span class="token operator">===</span><span class="token operator">===</span><span class="token operator">===</span><span class="token operator">===</span><span class="token operator">===</span><span class="token operator">===</span><span class="token operator">=</span><span class="token comment">//通过bind绑定</span><span class="token keyword">function</span> <span class="token function">Person</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token keyword">this</span><span class="token punctuation">.</span>age <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span> <span class="token function">setTimeout</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token keyword">function</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">bind</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token number">3000</span><span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token punctuation">}</span><span class="token keyword">var</span> p <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Person</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token comment">//3秒后返回构造函数新生成的对象 Person{...}</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre></li><li><p><strong>箭头函数中的 this</strong></p><pre class="line-numbers language-javascript" data-language="javascript"><code class="language-javascript"><span class="token keyword">function</span> <span class="token function">Person</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token keyword">this</span><span class="token punctuation">.</span>age <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span> <span class="token function">setInterval</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">=></span> <span class="token punctuation">{</span> <span class="token comment">// 回调里面的 `this` 变量就指向了期望的那个对象了</span> <span class="token keyword">this</span><span class="token punctuation">.</span>age<span class="token operator">++</span><span class="token punctuation">;</span> <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token number">3000</span><span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token punctuation">}</span><span class="token keyword">var</span> p <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Person</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token keyword">var</span> adder <span class="token operator">=</span> <span class="token punctuation">{</span> base<span class="token operator">:</span> <span class="token number">1</span><span class="token punctuation">,</span> <span class="token function-variable function">add</span><span class="token operator">:</span> <span class="token keyword">function</span> <span class="token punctuation">(</span><span class="token parameter">a</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token keyword">var</span> <span class="token function-variable function">f</span> <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token parameter">v</span><span class="token punctuation">)</span> <span class="token operator">=></span> v <span class="token operator">+</span> <span class="token keyword">this</span><span class="token punctuation">.</span>base<span class="token punctuation">;</span> <span class="token keyword">return</span> <span class="token function">f</span><span class="token punctuation">(</span>a<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token function-variable function">addThruCall</span><span class="token operator">:</span> <span class="token keyword">function</span> <span class="token function">inFun</span><span class="token punctuation">(</span><span class="token parameter">a</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token keyword">var</span> <span class="token function-variable function">f</span> <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token parameter">v</span><span class="token punctuation">)</span> <span class="token operator">=></span> v <span class="token operator">+</span> <span class="token keyword">this</span><span class="token punctuation">.</span>base<span class="token punctuation">;</span> <span class="token keyword">var</span> b <span class="token operator">=</span> <span class="token punctuation">{</span> base<span class="token operator">:</span> <span class="token number">2</span><span class="token punctuation">,</span> <span class="token punctuation">}</span><span class="token punctuation">;</span> <span class="token keyword">return</span> <span class="token function">f</span><span class="token punctuation">.</span><span class="token function">call</span><span class="token punctuation">(</span>b<span class="token punctuation">,</span> a<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token punctuation">}</span><span class="token punctuation">,</span><span class="token punctuation">}</span><span class="token punctuation">;</span>console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>adder<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// 输出 2</span>console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>adder<span class="token punctuation">.</span><span class="token function">addThruCall</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// 仍然输出 2(而不是3,其内部的this并没有因为call() 而改变,其this值仍然为函数inFun的this值,指向对象adder</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre><pre class="line-numbers language-javascript" data-language="javascript"><code class="language-javascript"><span class="token keyword">var</span> <span class="token function-variable function">f</span> <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">=></span> <span class="token punctuation">{</span> <span class="token string">"use strict"</span><span class="token punctuation">;</span> <span class="token keyword">return</span> <span class="token keyword">this</span><span class="token punctuation">;</span><span class="token punctuation">}</span><span class="token punctuation">;</span><span class="token keyword">var</span> <span class="token function-variable function">p</span> <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">=></span> <span class="token punctuation">{</span> <span class="token keyword">return</span> <span class="token keyword">this</span><span class="token punctuation">;</span><span class="token punctuation">}</span><span class="token punctuation">;</span>console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">,</span> <span class="token function">f</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">===</span> window<span class="token punctuation">)</span><span class="token punctuation">;</span>console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token number">2</span><span class="token punctuation">,</span> <span class="token function">f</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">===</span> <span class="token function">p</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token comment">//1 true</span><span class="token comment">//2 true</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre><p>以上的箭头函数都是在方法内部,总之都是以非方法的方式使用,如果将箭头函数当做一个方法使用会怎样呢?作为方法的箭头函数 this 指向全局 window 对象,而普通函数则指向调用它的对象。</p></li></ul></li><li><h3 id="可以使用-new-一个箭头函数么?"><a href="#可以使用-new-一个箭头函数么?" class="headerlink" title="可以使用 new 一个箭头函数么?"></a><strong>可以使用 new 一个箭头函数么?</strong></h3><p>箭头函数没有 prototype 也没有自己的 this 指向并且不可以使用 arguments。</p></li><li><h3 id="箭头函数和普通函数有什么区别"><a href="#箭头函数和普通函数有什么区别" class="headerlink" title="箭头函数和普通函数有什么区别"></a><strong>箭头函数和普通函数有什么区别</strong></h3><ul><li>语法更加简洁、清晰</li><li>箭头函数不会创建自己的 <code>this</code></li><li>箭头函数继承而来的 <code>this</code> 指向永远不变</li><li>.call()/.apply()/.bind() 无法改变箭头函数中 <code>this</code> 的指向</li><li>箭头函数没有原型 <code>prototype</code></li><li>箭头函数不能作为构造函数使用,不能用 <code>new</code></li><li>箭头函数没有自己的 <code>arguments</code></li></ul></li><li><h3 id="new-的实现"><a href="#new-的实现" class="headerlink" title="new 的实现"></a><strong>new 的实现</strong></h3><pre class="line-numbers language-javascript" data-language="javascript"><code class="language-javascript"><span class="token keyword">function</span> <span class="token function">create</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token comment">// 创建一个空对象</span> <span class="token keyword">let</span> obj <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Object</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// 获取构造函数</span> <span class="token keyword">let</span> Con <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">.</span><span class="token function">shift</span><span class="token punctuation">.</span><span class="token function">call</span><span class="token punctuation">(</span>arguments<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// 将对象(实例)的 __proto__ 和构造函数的 prototype 绑定</span> obj<span class="token punctuation">.</span>__proto__ <span class="token operator">=</span> <span class="token class-name">Con</span><span class="token punctuation">.</span>prototype<span class="token punctuation">;</span> <span class="token comment">// 绑定this,以及参数</span> <span class="token keyword">let</span> result <span class="token operator">=</span> <span class="token function">Con</span><span class="token punctuation">.</span><span class="token function">apply</span><span class="token punctuation">(</span>obj<span class="token punctuation">,</span> arguments<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// 确保返回的是对象</span> <span class="token keyword">return</span> <span class="token keyword">typeof</span> result <span class="token operator">===</span> <span class="token string">"object"</span> <span class="token operator">?</span> result <span class="token operator">:</span> obj<span class="token punctuation">;</span><span class="token punctuation">}</span><span class="token keyword">function</span> <span class="token function">Person</span><span class="token punctuation">(</span><span class="token parameter">name</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token keyword">this</span><span class="token punctuation">.</span>name <span class="token operator">=</span> name<span class="token punctuation">;</span> <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function-variable function">say</span> <span class="token operator">=</span> <span class="token keyword">function</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token string">"name = "</span> <span class="token operator">+</span> <span class="token keyword">this</span><span class="token punctuation">.</span>name<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token punctuation">}</span><span class="token punctuation">;</span><span class="token punctuation">}</span><span class="token keyword">var</span> person <span class="token operator">=</span> <span class="token function">create</span><span class="token punctuation">(</span>Person<span class="token punctuation">,</span> <span class="token string">"a"</span><span class="token punctuation">)</span><span class="token punctuation">;</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre></li><li><h3 id="instanceof-的原理"><a href="#instanceof-的原理" class="headerlink" title="instanceof 的原理"></a><strong>instanceof 的原理</strong></h3><pre class="line-numbers language-javascript" data-language="javascript"><code class="language-javascript"><span class="token keyword">function</span> <span class="token function">new_instance_of</span><span class="token punctuation">(</span><span class="token parameter">leftVaule<span class="token punctuation">,</span> rightVaule</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token keyword">let</span> rightProto <span class="token operator">=</span> rightVaule<span class="token punctuation">.</span>prototype<span class="token punctuation">;</span> <span class="token comment">// 取右表达式的 prototype 值</span> leftVaule <span class="token operator">=</span> leftVaule<span class="token punctuation">.</span>__proto__<span class="token punctuation">;</span> <span class="token comment">// 取左表达式的__proto__值</span> <span class="token keyword">while</span> <span class="token punctuation">(</span><span class="token boolean">true</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token keyword">if</span> <span class="token punctuation">(</span>leftVaule <span class="token operator">===</span> <span class="token keyword">null</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token keyword">return</span> <span class="token boolean">false</span><span class="token punctuation">;</span> <span class="token punctuation">}</span> <span class="token keyword">if</span> <span class="token punctuation">(</span>leftVaule <span class="token operator">===</span> rightProto<span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token keyword">return</span> <span class="token boolean">true</span><span class="token punctuation">;</span> <span class="token punctuation">}</span> leftVaule <span class="token operator">=</span> leftVaule<span class="token punctuation">.</span>__proto__<span class="token punctuation">;</span> <span class="token punctuation">}</span><span class="token punctuation">}</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre></li><li><h3 id="cookie、localStorage-和-sessionStorage-的区别"><a href="#cookie、localStorage-和-sessionStorage-的区别" class="headerlink" title="cookie、localStorage 和 sessionStorage 的区别"></a><strong>cookie、localStorage 和 sessionStorage 的区别</strong></h3><ul><li><h4 id="Cookie"><a href="#Cookie" class="headerlink" title="Cookie"></a>Cookie</h4><p>Cookie 是小甜饼的意思。顾名思义,cookie 确实非常小,它的大小限制为 4KB 左右。它的主要用途有保存登录信息,比如你登录某个网站市场可以看到“记住密码”,这通常就是通过在 Cookie 中存入一段辨别用户身份的数据来实现的。</p></li><li><h4 id="localStorage"><a href="#localStorage" class="headerlink" title="localStorage"></a>localStorage</h4><p>localStorage 是 HTML5 标准中新加入的技术,它并不是什么划时代的新东西。早在 IE 6 时代,就有一个叫 userData 的东西用于本地存储,而当时考虑到浏览器兼容性,更通用的方案是使用 Flash。而如今,localStorage 被大多数浏览器所支持,如果你的网站需要支持 IE6+,那以 userData 作为你的 polyfill 的方案是种不错的选择。</p></li><li><h4 id="sessionStorage"><a href="#sessionStorage" class="headerlink" title="sessionStorage"></a>sessionStorage</h4><p>sessionStorage 与 localStorage 的接口类似,但保存数据的生命周期与 localStorage 不同。做过后端开发的同学应该知道 Session 这个词的意思,直译过来是“会话”。而 sessionStorage 是一个前端的概念,它只是可以将一部分数据在当前会话中保存下来,刷新页面数据依旧存在。但当页面关闭后,sessionStorage 中的数据就会被清空。</p></li></ul></li></ol>]]></content>
<categories>
<category> 技术文档 </category>
</categories>
<tags>
<tag> 前端 </tag>
<tag> JavaScript </tag>
<tag> css </tag>
<tag> HTML </tag>
</tags>
</entry>
<entry>
<title>用Python爬取厚生劳动省派遣公司数据</title>
<link href="/2021/07/02/yong-python-pa-qu-hou-sheng-lao-dong-sheng-pai-qian-gong-si-shu-ju/"/>
<url>/2021/07/02/yong-python-pa-qu-hou-sheng-lao-dong-sheng-pai-qian-gong-si-shu-ju/</url>
<content type="html"><![CDATA[<h1 id="用Python爬取厚生劳动省派遣公司数据"><a href="#用Python爬取厚生劳动省派遣公司数据" class="headerlink" title="用Python爬取厚生劳动省派遣公司数据"></a>用Python爬取厚生劳动省派遣公司数据</h1><h2 id="一、爬虫前的准备"><a href="#一、爬虫前的准备" class="headerlink" title="一、爬虫前的准备"></a>一、爬虫前的准备</h2><p>需要的技术知识</p><ul><li>js、html</li><li>Python</li><li>抓包</li><li>BeautifulSoup</li></ul><p>厚生劳动省的查询网站:<a href="https://jinzai.hellowork.mhlw.go.jp/JinzaiWeb/GICB102010.do">https://jinzai.hellowork.mhlw.go.jp/JinzaiWeb/GICB102010.do</a></p><h2 id="二、分析数据传输"><a href="#二、分析数据传输" class="headerlink" title="二、分析数据传输"></a>二、分析数据传输</h2><p>我们可以看到网站中有一系列筛选条件,我主要关注的是东京地区的公司,所以这里只对东京进行分析,其他的条件自行修改参数即可。我们按F12浏览器开发者模式,进入Network标签页,在页面上选择东京,点击检索。</p><p><img src="https://i.loli.net/2021/07/02/nihXtIgFCA6zVkG.png" alt="检索"></p><p>我们可以观察到Network的变化,其中GICB102010.do就是我们需要的</p><p><img src="https://i.loli.net/2021/07/02/H3ArwghYXf7VmCj.png" alt="抓包"></p><p>点击查看详情,在Headers部分可以看到它的一些基本信息,包括响应头、请求头和请求体等。</p><p><img src="https://i.loli.net/2021/07/02/O4rg5oPtdbHSJTC.png" alt="网络传输数据"></p><p><img src="https://i.loli.net/2021/07/02/9WSYwoGfvcAlmgB.png" alt="请求体参数数据"><br>这里的action参数,我们检索的时候为“search”,分页的时候为“page”。</p><p>接下来我们将用到图片中的数据进行网页信息的获取</p><h2 id="三、利用PostJson测试能否获取网页信息"><a href="#三、利用PostJson测试能否获取网页信息" class="headerlink" title="三、利用PostJson测试能否获取网页信息"></a>三、利用PostJson测试能否获取网页信息</h2><p>PostJson网址:<a href="http://coolaf.com/tool/post">http://coolaf.com/tool/post</a></p><p>我们将第二步获取的数据填入对应的模块中,它这里用的是Post传参,通过表单进行提交,application/x-www-form-urlencoded,在PostJson中我们选择x-www-form-urlencoded,Cookie选择AREA,输入Cookie,也就是第二步请求头中的Cookies,Headers对应第二步请求头的信息。</p><p><img src="https://i.loli.net/2021/07/02/MBt9PTVsaUwq6kf.png" alt="PostJson"></p><p>点击提交,可以看到,它返回了网站的源代码,效果和我们在查询页面右键点击查看网页源代码一样。</p><h2 id="四、分析网页"><a href="#四、分析网页" class="headerlink" title="四、分析网页"></a>四、分析网页</h2><p><img src="https://i.loli.net/2021/07/02/8kCV7IYUGBrAtWn.png" alt="公司信息表"></p><p>可以看到,总共有12519家公司,而这里采取的分页查询,所以之后我们在进行代码编写的时候,要动态的改变页码参数去循环获取每页的数据。图中表格中的内容就是我们需要的公司信息,右键查看网页源代码。我们找到表格的部分,发现这个表格的id=‘search’,除去第一个为表头,每个公司都在这个表格中占一个。</p><h2 id="五、代码编写"><a href="#五、代码编写" class="headerlink" title="五、代码编写"></a>五、代码编写</h2><pre class="line-numbers language-python" data-language="python"><code class="language-python"><span class="token keyword">import</span> requests<span class="token keyword">from</span> bs4 <span class="token keyword">import</span> BeautifulSoup<span class="token comment">#全局变量</span>Num <span class="token operator">=</span> <span class="token number">0</span><span class="token comment">#获取网站信息</span><span class="token keyword">def</span> <span class="token function">getHTMLText</span><span class="token punctuation">(</span>url<span class="token punctuation">,</span>page<span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token keyword">try</span><span class="token punctuation">:</span> <span class="token comment">#访问网站需要的数据参数</span> data <span class="token operator">=</span> <span class="token punctuation">{</span> <span class="token string">'params'</span><span class="token punctuation">:</span>page<span class="token punctuation">,</span> <span class="token string">'hfCond'</span><span class="token punctuation">:</span><span class="token string">'3mLVm+1L2TF3qSHhXVWLKO2UWAiGJtJ7tzx5ZHVkjZss7jxUSh1jh0ECe+YsZSuzlTMpAfvEs/stliWTLD/MP/D1zphgZT7Fyfpuc5N32Tw='</span><span class="token punctuation">,</span> <span class="token string">'curPage'</span><span class="token punctuation">:</span><span class="token string">'1'</span><span class="token punctuation">,</span> <span class="token string">'cbTokyo'</span><span class="token punctuation">:</span><span class="token string">'1'</span><span class="token punctuation">,</span> <span class="token string">'ucKyokatodokedeNo1'</span><span class="token punctuation">:</span> <span class="token string">''</span><span class="token punctuation">,</span> <span class="token string">'txtKyokatodokedeNo2'</span><span class="token punctuation">:</span> <span class="token string">''</span><span class="token punctuation">,</span> <span class="token string">'txtKyokatodokedeNo3'</span><span class="token punctuation">:</span> <span class="token string">''</span><span class="token punctuation">,</span> <span class="token comment"># 'nm_btnSearch.x': '88',</span> <span class="token comment"># 'nm_btnSearch.y': '26',</span> <span class="token string">'hfJigyoshoRegKbn'</span><span class="token punctuation">:</span> <span class="token string">'0'</span><span class="token punctuation">,</span> <span class="token string">'hfScrollTop'</span><span class="token punctuation">:</span> <span class="token string">'1500'</span><span class="token punctuation">,</span> <span class="token string">'screenId'</span><span class="token punctuation">:</span> <span class="token string">'GICB102010'</span><span class="token punctuation">,</span> <span class="token string">'action'</span><span class="token punctuation">:</span> <span class="token string">'page'</span><span class="token punctuation">,</span> <span class="token string">'codeAssistType'</span><span class="token punctuation">:</span> <span class="token string">''</span><span class="token punctuation">,</span> <span class="token string">'codeAssistKind'</span><span class="token punctuation">:</span> <span class="token string">''</span><span class="token punctuation">,</span> <span class="token string">'codeAssistCode'</span><span class="token punctuation">:</span> <span class="token string">''</span><span class="token punctuation">,</span> <span class="token string">'codeAssistItemCode'</span><span class="token punctuation">:</span> <span class="token string">''</span><span class="token punctuation">,</span> <span class="token string">'codeAssistItemName'</span><span class="token punctuation">:</span> <span class="token string">''</span><span class="token punctuation">,</span> <span class="token string">'codeAssistDivide'</span><span class="token punctuation">:</span> <span class="token string">''</span><span class="token punctuation">,</span> <span class="token string">'maba_vrbs'</span><span class="token punctuation">:</span><span class="token string">''</span> <span class="token punctuation">}</span> <span class="token comment">#头部协议</span> headers <span class="token operator">=</span> <span class="token punctuation">{</span> <span class="token string">'Accept'</span><span class="token punctuation">:</span><span class="token string">'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9'</span><span class="token punctuation">,</span> <span class="token string">'Accept-Encoding'</span><span class="token punctuation">:</span><span class="token string">'gzip, deflate, br'</span><span class="token punctuation">,</span> <span class="token string">'Accept-Language'</span><span class="token punctuation">:</span><span class="token string">'ja,en-US;q=0.9,en;q=0.8,zh-CN;q=0.7,zh;q=0.6'</span><span class="token punctuation">,</span> <span class="token string">'Cache-Control'</span><span class="token punctuation">:</span><span class="token string">'max-age=0'</span><span class="token punctuation">,</span> <span class="token string">'Connection'</span><span class="token punctuation">:</span><span class="token string">'keep-alive'</span><span class="token punctuation">,</span> <span class="token string">'Content-Length'</span><span class="token punctuation">:</span><span class="token string">'440'</span><span class="token punctuation">,</span> <span class="token string">'Content-Type'</span><span class="token punctuation">:</span><span class="token string">'application/x-www-form-urlencoded'</span><span class="token punctuation">,</span> <span class="token string">'Cookie'</span><span class="token punctuation">:</span><span class="token string">'JSESSIONID=tnokZeolLdfwYSKnpNpNT34yVuwNXF4W6o68yuN1Cs_mup_yrQai0Nfap8b-0EDR.ICB_001'</span> <span class="token punctuation">}</span> r <span class="token operator">=</span> requests<span class="token punctuation">.</span>post<span class="token punctuation">(</span>url<span class="token operator">=</span>url<span class="token punctuation">,</span> data<span class="token operator">=</span>data<span class="token punctuation">,</span> headers<span class="token operator">=</span>headers<span class="token punctuation">)</span> r<span class="token punctuation">.</span>raise_for_status<span class="token punctuation">(</span><span class="token punctuation">)</span> r<span class="token punctuation">.</span>encoding <span class="token operator">=</span> r<span class="token punctuation">.</span>apparent_encoding <span class="token keyword">return</span> r<span class="token punctuation">.</span>text <span class="token keyword">except</span><span class="token punctuation">:</span> <span class="token keyword">return</span> <span class="token string">""</span><span class="token comment">#循环进行分页操作获取数据</span><span class="token keyword">def</span> <span class="token function">get_html</span><span class="token punctuation">(</span>url<span class="token punctuation">,</span>fpath<span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token keyword">for</span> i <span class="token keyword">in</span> <span class="token builtin">range</span><span class="token punctuation">(</span><span class="token number">626</span><span class="token punctuation">)</span><span class="token punctuation">:</span> page <span class="token operator">=</span> i<span class="token operator">+</span><span class="token number">1</span> html <span class="token operator">=</span> getHTMLText<span class="token punctuation">(</span>url<span class="token punctuation">,</span> page<span class="token punctuation">)</span> getCompany<span class="token punctuation">(</span>html<span class="token punctuation">,</span>fpath<span class="token punctuation">)</span><span class="token comment">#获取每页的公司信息</span><span class="token keyword">def</span> <span class="token function">getCompany</span><span class="token punctuation">(</span>html<span class="token punctuation">,</span> fpath<span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token keyword">global</span> Num soup <span class="token operator">=</span> BeautifulSoup<span class="token punctuation">(</span>html<span class="token punctuation">,</span><span class="token string">'html.parser'</span><span class="token punctuation">)</span> <span class="token comment">#找到公司信息的表格</span> table <span class="token operator">=</span> soup<span class="token punctuation">.</span>find<span class="token punctuation">(</span><span class="token builtin">id</span><span class="token operator">=</span><span class="token string">'search'</span><span class="token punctuation">)</span> <span class="token comment">#除去表头,对每一行进行循环</span> <span class="token keyword">for</span> tr <span class="token keyword">in</span> table<span class="token punctuation">.</span>find_all<span class="token punctuation">(</span><span class="token string">'tr'</span><span class="token punctuation">)</span><span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">:</span><span class="token punctuation">]</span><span class="token punctuation">:</span> <span class="token keyword">try</span><span class="token punctuation">:</span> infoDict <span class="token operator">=</span> <span class="token punctuation">{</span><span class="token punctuation">}</span> infoDict<span class="token punctuation">[</span><span class="token string">'Num'</span><span class="token punctuation">]</span> <span class="token operator">=</span> Num infoDict<span class="token punctuation">[</span><span class="token string">'許可・受理番号'</span><span class="token punctuation">]</span> <span class="token operator">=</span> tr<span class="token punctuation">.</span>find<span class="token punctuation">(</span><span class="token builtin">id</span><span class="token operator">=</span><span class="token string">'ID_lbKyokatodokedeNo'</span><span class="token punctuation">)</span><span class="token punctuation">.</span>string infoDict<span class="token punctuation">[</span><span class="token string">'許可年月日・届出受理年月日'</span><span class="token punctuation">]</span> <span class="token operator">=</span> tr<span class="token punctuation">.</span>find<span class="token punctuation">(</span><span class="token builtin">id</span><span class="token operator">=</span><span class="token string">'ID_lbKyokatodokedeDate'</span><span class="token punctuation">)</span><span class="token punctuation">.</span>string infoDict<span class="token punctuation">[</span><span class="token string">'事業主名称'</span><span class="token punctuation">]</span> <span class="token operator">=</span> tr<span class="token punctuation">.</span>find<span class="token punctuation">(</span><span class="token builtin">id</span><span class="token operator">=</span><span class="token string">'ID_lbJigyonushiName'</span><span class="token punctuation">)</span><span class="token punctuation">.</span>string<span class="token punctuation">.</span>replace<span class="token punctuation">(</span><span class="token string">u'\u3000'</span><span class="token punctuation">,</span> <span class="token string">u''</span><span class="token punctuation">)</span> infoDict<span class="token punctuation">[</span><span class="token string">'事業所名称'</span><span class="token punctuation">]</span> <span class="token operator">=</span> tr<span class="token punctuation">.</span>find<span class="token punctuation">(</span><span class="token builtin">id</span><span class="token operator">=</span><span class="token string">'ID_lbJigyoshoName'</span><span class="token punctuation">)</span><span class="token punctuation">.</span>string<span class="token punctuation">.</span>replace<span class="token punctuation">(</span><span class="token string">u'\u3000'</span><span class="token punctuation">,</span> <span class="token string">u''</span><span class="token punctuation">)</span> infoDict<span class="token punctuation">[</span><span class="token string">'事業所所在地'</span><span class="token punctuation">]</span> <span class="token operator">=</span> tr<span class="token punctuation">.</span>find<span class="token punctuation">(</span><span class="token builtin">id</span><span class="token operator">=</span><span class="token string">'ID_lbJigyoshoAddress'</span><span class="token punctuation">)</span><span class="token punctuation">.</span>string<span class="token punctuation">.</span>replace<span class="token punctuation">(</span><span class="token string">u'\u3000'</span><span class="token punctuation">,</span> <span class="token string">u''</span><span class="token punctuation">)</span> infoDict<span class="token punctuation">[</span><span class="token string">'電話番号'</span><span class="token punctuation">]</span> <span class="token operator">=</span> tr<span class="token punctuation">.</span>find<span class="token punctuation">(</span><span class="token builtin">id</span><span class="token operator">=</span><span class="token string">'ID_lbTel'</span><span class="token punctuation">)</span><span class="token punctuation">.</span>string Num <span class="token operator">=</span> Num <span class="token operator">+</span> <span class="token number">1</span> <span class="token keyword">if</span> tr<span class="token punctuation">.</span>find<span class="token punctuation">(</span><span class="token builtin">id</span><span class="token operator">=</span><span class="token string">'ID_lbRyokinaveValue'</span><span class="token punctuation">)</span><span class="token punctuation">:</span> infoDict<span class="token punctuation">[</span><span class="token string">'派遣料金の平均額'</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token string">''</span><span class="token punctuation">.</span>join<span class="token punctuation">(</span>tr<span class="token punctuation">.</span>find<span class="token punctuation">(</span><span class="token builtin">id</span><span class="token operator">=</span><span class="token string">'ID_lbRyokinaveValue'</span><span class="token punctuation">)</span><span class="token punctuation">.</span>parent<span class="token punctuation">.</span>stripped_strings<span class="token punctuation">)</span> <span class="token keyword">if</span> tr<span class="token punctuation">.</span>find<span class="token punctuation">(</span><span class="token builtin">id</span><span class="token operator">=</span><span class="token string">'ID_lbChinginaveValue'</span><span class="token punctuation">)</span><span class="token punctuation">:</span> infoDict<span class="token punctuation">[</span><span class="token string">'派遣労働者の賃金の平均額'</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token string">''</span><span class="token punctuation">.</span>join<span class="token punctuation">(</span>tr<span class="token punctuation">.</span>find<span class="token punctuation">(</span><span class="token builtin">id</span><span class="token operator">=</span><span class="token string">'ID_lbChinginaveValue'</span><span class="token punctuation">)</span><span class="token punctuation">.</span>parent<span class="token punctuation">.</span>stripped_strings<span class="token punctuation">)</span> <span class="token keyword">if</span> tr<span class="token punctuation">.</span>find<span class="token punctuation">(</span><span class="token builtin">id</span><span class="token operator">=</span><span class="token string">'ID_lbPMargin'</span><span class="token punctuation">)</span><span class="token punctuation">:</span> infoDict<span class="token punctuation">[</span><span class="token string">'マージン率'</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token string">''</span><span class="token punctuation">.</span>join<span class="token punctuation">(</span>tr<span class="token punctuation">.</span>find<span class="token punctuation">(</span><span class="token builtin">id</span><span class="token operator">=</span><span class="token string">'ID_lbPMargin'</span><span class="token punctuation">)</span><span class="token punctuation">.</span>parent<span class="token punctuation">.</span>stripped_strings<span class="token punctuation">)</span> <span class="token keyword">if</span> tr<span class="token punctuation">.</span>find<span class="token punctuation">(</span><span class="token builtin">id</span><span class="token operator">=</span><span class="token string">'ID_lbRoshikyoteiShuuki'</span><span class="token punctuation">)</span><span class="token punctuation">:</span> infoDict<span class="token punctuation">[</span><span class="token string">'労使協定の締結'</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token string">''</span><span class="token punctuation">.</span>join<span class="token punctuation">(</span>tr<span class="token punctuation">.</span>find<span class="token punctuation">(</span><span class="token builtin">id</span><span class="token operator">=</span><span class="token string">'ID_lbRoshikyoteiShuuki'</span><span class="token punctuation">)</span><span class="token punctuation">.</span>parent<span class="token punctuation">.</span>stripped_strings<span class="token punctuation">)</span> <span class="token keyword">if</span> tr<span class="token punctuation">.</span>find<span class="token punctuation">(</span><span class="token builtin">id</span><span class="token operator">=</span><span class="token string">'ID_lbYuryou'</span><span class="token punctuation">)</span><span class="token punctuation">:</span> infoDict<span class="token punctuation">[</span><span class="token string">'備考'</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token string">''</span><span class="token punctuation">.</span>join<span class="token punctuation">(</span>tr<span class="token punctuation">.</span>find<span class="token punctuation">(</span><span class="token builtin">id</span><span class="token operator">=</span><span class="token string">'ID_lbYuryou'</span><span class="token punctuation">)</span><span class="token punctuation">.</span>parent<span class="token punctuation">.</span>stripped_strings<span class="token punctuation">)</span> <span class="token keyword">print</span><span class="token punctuation">(</span>infoDict<span class="token punctuation">)</span> <span class="token comment">#保存到文件中</span> <span class="token keyword">with</span> <span class="token builtin">open</span><span class="token punctuation">(</span>fpath<span class="token punctuation">,</span> <span class="token string">'a'</span><span class="token punctuation">,</span> encoding<span class="token operator">=</span><span class="token string">'utf-8'</span><span class="token punctuation">)</span> <span class="token keyword">as</span> f<span class="token punctuation">:</span> f<span class="token punctuation">.</span>write<span class="token punctuation">(</span><span class="token builtin">str</span><span class="token punctuation">(</span>infoDict<span class="token punctuation">)</span> <span class="token operator">+</span> <span class="token string">'\n'</span><span class="token punctuation">)</span> <span class="token keyword">except</span><span class="token punctuation">:</span> <span class="token keyword">continue</span><span class="token keyword">def</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token comment">#爬取的网站信息</span> url <span class="token operator">=</span> <span class="token string">'https://jinzai.hellowork.mhlw.go.jp/JinzaiWeb/GICB102010.do'</span> <span class="token comment">#文件保存的地址</span> output_file <span class="token operator">=</span> <span class="token string">'D://python//data//info.txt'</span> get_html<span class="token punctuation">(</span>url<span class="token punctuation">,</span>output_file<span class="token punctuation">)</span>main<span class="token punctuation">(</span><span class="token punctuation">)</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>]]></content>
<categories>
<category> 技术文档 </category>
</categories>
<tags>
<tag> Python </tag>
<tag> js </tag>
<tag> Html </tag>
</tags>
</entry>
<entry>
<title>BigQuant代码锦集</title>
<link href="/2021/06/25/bigquant-dai-ma-jin-ji/"/>
<url>/2021/06/25/bigquant-dai-ma-jin-ji/</url>
<content type="html"><![CDATA[<h1 id="BigQuant代码锦集"><a href="#BigQuant代码锦集" class="headerlink" title="BigQuant代码锦集"></a>BigQuant代码锦集</h1><p> 这里是平常工作中会用到的一些常用的代码集合,不定时的更新❀</p><hr><h4 id="股票池中去除获取创业板代码"><a href="#股票池中去除获取创业板代码" class="headerlink" title="股票池中去除获取创业板代码"></a>股票池中去除获取创业板代码</h4><pre class="line-numbers language-python" data-language="python"><code class="language-python">all_ins <span class="token operator">=</span> D<span class="token punctuation">.</span>instruments<span class="token punctuation">(</span>start_date<span class="token operator">=</span><span class="token string">'2017-09-07'</span><span class="token punctuation">,</span>end_date<span class="token operator">=</span><span class="token string">'2018-09-07'</span><span class="token punctuation">)</span><span class="token comment">#创业板代码一般以3开头</span>ins <span class="token operator">=</span> <span class="token punctuation">[</span>k <span class="token keyword">for</span> k <span class="token keyword">in</span> all_ins <span class="token keyword">if</span> k<span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span><span class="token operator">==</span><span class="token string">'8'</span><span class="token punctuation">]</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span></span></code></pre><h4 id="求股票的真实价格"><a href="#求股票的真实价格" class="headerlink" title="求股票的真实价格"></a>求股票的真实价格</h4><pre class="line-numbers language-python" data-language="python"><code class="language-python">start <span class="token operator">=</span> <span class="token string">'2018-11-23'</span>end <span class="token operator">=</span> <span class="token string">'2019-12-20'</span>features_data <span class="token operator">=</span> D<span class="token punctuation">.</span>features<span class="token punctuation">(</span>D<span class="token punctuation">.</span>instruments<span class="token punctuation">(</span>start<span class="token punctuation">,</span> end<span class="token punctuation">)</span><span class="token punctuation">,</span> start<span class="token punctuation">,</span> end<span class="token punctuation">,</span> <span class="token punctuation">[</span><span class="token string">'close_0'</span><span class="token punctuation">,</span><span class="token string">'close_1'</span><span class="token punctuation">,</span><span class="token string">'close_2'</span><span class="token punctuation">,</span><span class="token string">'volume_0'</span><span class="token punctuation">,</span><span class="token string">'industry_sw_level1_0'</span><span class="token punctuation">,</span><span class="token string">'daily_return_0'</span><span class="token punctuation">,</span><span class="token string">'adjust_factor_0'</span><span class="token punctuation">]</span><span class="token punctuation">)</span>features_data <span class="token operator">=</span> features_data<span class="token punctuation">[</span>features_data<span class="token punctuation">[</span><span class="token string">'instrument'</span><span class="token punctuation">]</span><span class="token operator">==</span><span class="token string">'002679.SZA'</span><span class="token punctuation">]</span><span class="token comment"># features_data['date'] = pd.to_datetime(features_data['date']) #将数据类型转换为日期类型</span>features_data <span class="token operator">=</span> features_data<span class="token punctuation">.</span>set_index<span class="token punctuation">(</span><span class="token string">'date'</span><span class="token punctuation">)</span> <span class="token comment"># 将date设置为index</span>features_data <span class="token operator">=</span> features_data<span class="token punctuation">.</span>sort_values<span class="token punctuation">(</span><span class="token string">'date'</span><span class="token punctuation">)</span><span class="token comment">#获取真实价格</span>features_data<span class="token punctuation">[</span><span class="token string">'close_0'</span><span class="token punctuation">]</span> <span class="token operator">/=</span> features_data<span class="token punctuation">[</span><span class="token string">'adjust_factor_0'</span><span class="token punctuation">]</span>features_data<span class="token punctuation">[</span><span class="token string">'close_1'</span><span class="token punctuation">]</span> <span class="token operator">/=</span> features_data<span class="token punctuation">[</span><span class="token string">'adjust_factor_0'</span><span class="token punctuation">]</span>features_data<span class="token punctuation">[</span><span class="token string">'close_2'</span><span class="token punctuation">]</span> <span class="token operator">/=</span> features_data<span class="token punctuation">[</span><span class="token string">'adjust_factor_0'</span><span class="token punctuation">]</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre><h4 id="筛选申万行业一的数据"><a href="#筛选申万行业一的数据" class="headerlink" title="筛选申万行业一的数据"></a>筛选申万行业一的数据</h4><pre class="line-numbers language-python" data-language="python"><code class="language-python">bar1d <span class="token operator">=</span> DataSource<span class="token punctuation">(</span><span class="token string">"bar1d_index_CN_STOCK_A"</span><span class="token punctuation">)</span><span class="token punctuation">.</span>read<span class="token punctuation">(</span>start_date<span class="token operator">=</span>start<span class="token punctuation">,</span>end_date<span class="token operator">=</span>end<span class="token punctuation">)</span><span class="token comment">#指数行情</span>bar1d_sw <span class="token operator">=</span> bar1d<span class="token punctuation">[</span>bar1d<span class="token punctuation">.</span>instrument<span class="token punctuation">.</span><span class="token builtin">str</span><span class="token punctuation">.</span>contains<span class="token punctuation">(</span><span class="token string">"SW"</span><span class="token punctuation">)</span><span class="token punctuation">]</span> <span class="token comment"># 筛选出申万行业指数</span>bar1d_sw<span class="token punctuation">[</span><span class="token string">'code'</span><span class="token punctuation">]</span> <span class="token operator">=</span> bar1d_sw<span class="token punctuation">[</span><span class="token string">'instrument'</span><span class="token punctuation">]</span><span class="token punctuation">.</span><span class="token builtin">apply</span><span class="token punctuation">(</span><span class="token keyword">lambda</span> x<span class="token punctuation">:</span> x<span class="token punctuation">.</span>split<span class="token punctuation">(</span><span class="token string">'.'</span><span class="token punctuation">)</span><span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span><span class="token punctuation">)</span>basic_info_sw <span class="token operator">=</span> DataSource<span class="token punctuation">(</span><span class="token string">"basic_info_IndustrySw"</span><span class="token punctuation">)</span><span class="token punctuation">.</span>read<span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token comment"># 读取申万行业基本信息数据</span>basic_info_sw<span class="token punctuation">[</span><span class="token string">'code'</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token string">"SW"</span> <span class="token operator">+</span> basic_info_sw<span class="token punctuation">[</span><span class="token string">'code'</span><span class="token punctuation">]</span>df3 <span class="token operator">=</span> bar1d_sw<span class="token punctuation">.</span>merge<span class="token punctuation">(</span>basic_info_sw<span class="token punctuation">,</span> on<span class="token operator">=</span><span class="token string">'code'</span><span class="token punctuation">,</span> how<span class="token operator">=</span><span class="token string">'left'</span><span class="token punctuation">)</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre><h4 id="展开全部行-x2F-列"><a href="#展开全部行-x2F-列" class="headerlink" title="展开全部行/列"></a>展开全部行/列</h4><pre class="line-numbers language-python" data-language="python"><code class="language-python">pd<span class="token punctuation">.</span>set_option<span class="token punctuation">(</span><span class="token string">'display.max_columns'</span><span class="token punctuation">,</span> <span class="token boolean">None</span><span class="token punctuation">)</span>pd<span class="token punctuation">.</span>set_option<span class="token punctuation">(</span><span class="token string">'display.max_rows'</span><span class="token punctuation">,</span> <span class="token boolean">None</span><span class="token punctuation">)</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span></span></code></pre><h4 id="计算均值"><a href="#计算均值" class="headerlink" title="计算均值"></a>计算均值</h4><pre class="line-numbers language-python" data-language="python"><code class="language-python">df<span class="token punctuation">[</span><span class="token string">'mean_5'</span><span class="token punctuation">]</span> <span class="token operator">=</span> df<span class="token punctuation">[</span><span class="token string">'close'</span><span class="token punctuation">]</span><span class="token punctuation">.</span>rolling<span class="token punctuation">(</span><span class="token number">5</span><span class="token punctuation">)</span><span class="token punctuation">.</span>mean<span class="token punctuation">(</span><span class="token punctuation">)</span>df<span class="token punctuation">[</span><span class="token string">'mean_10'</span><span class="token punctuation">]</span> <span class="token operator">=</span> df<span class="token punctuation">[</span><span class="token string">'close'</span><span class="token punctuation">]</span><span class="token punctuation">.</span>rolling<span class="token punctuation">(</span><span class="token number">10</span><span class="token punctuation">)</span><span class="token punctuation">.</span>mean<span class="token punctuation">(</span><span class="token punctuation">)</span>df<span class="token punctuation">[</span><span class="token string">'mean_20'</span><span class="token punctuation">]</span> <span class="token operator">=</span> df<span class="token punctuation">[</span><span class="token string">'close'</span><span class="token punctuation">]</span><span class="token punctuation">.</span>rolling<span class="token punctuation">(</span><span class="token number">20</span><span class="token punctuation">)</span><span class="token punctuation">.</span>mean<span class="token punctuation">(</span><span class="token punctuation">)</span>df<span class="token punctuation">[</span><span class="token string">'mean_60'</span><span class="token punctuation">]</span> <span class="token operator">=</span> df<span class="token punctuation">[</span><span class="token string">'close'</span><span class="token punctuation">]</span><span class="token punctuation">.</span>rolling<span class="token punctuation">(</span><span class="token number">60</span><span class="token punctuation">)</span><span class="token punctuation">.</span>mean<span class="token punctuation">(</span><span class="token punctuation">)</span>df<span class="token punctuation">[</span><span class="token string">'mean_120'</span><span class="token punctuation">]</span> <span class="token operator">=</span> df<span class="token punctuation">[</span><span class="token string">'close'</span><span class="token punctuation">]</span><span class="token punctuation">.</span>rolling<span class="token punctuation">(</span><span class="token number">120</span><span class="token punctuation">)</span><span class="token punctuation">.</span>mean<span class="token punctuation">(</span><span class="token punctuation">)</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span></span></code></pre><h4 id="计算角度"><a href="#计算角度" class="headerlink" title="计算角度"></a>计算角度</h4><pre class="line-numbers language-python" data-language="python"><code class="language-python">df<span class="token punctuation">[</span><span class="token string">'arctan_5'</span><span class="token punctuation">]</span> <span class="token operator">=</span> np<span class="token punctuation">.</span>arctan<span class="token punctuation">(</span><span class="token punctuation">(</span>df<span class="token punctuation">[</span><span class="token string">'mean_5'</span><span class="token punctuation">]</span><span class="token operator">/</span>df<span class="token punctuation">[</span><span class="token string">'mean_5'</span><span class="token punctuation">]</span><span class="token punctuation">.</span>shift<span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">)</span><span class="token operator">-</span><span class="token number">1</span><span class="token punctuation">)</span><span class="token operator">*</span><span class="token number">100</span><span class="token punctuation">)</span><span class="token operator">*</span><span class="token number">180</span><span class="token operator">/</span><span class="token number">3.1416</span>df<span class="token punctuation">[</span><span class="token string">'arctan_10'</span><span class="token punctuation">]</span> <span class="token operator">=</span> np<span class="token punctuation">.</span>arctan<span class="token punctuation">(</span><span class="token punctuation">(</span>df<span class="token punctuation">[</span><span class="token string">'mean_10'</span><span class="token punctuation">]</span><span class="token operator">/</span>df<span class="token punctuation">[</span><span class="token string">'mean_10'</span><span class="token punctuation">]</span><span class="token punctuation">.</span>shift<span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">)</span><span class="token operator">-</span><span class="token number">1</span><span class="token punctuation">)</span><span class="token operator">*</span><span class="token number">100</span><span class="token punctuation">)</span><span class="token operator">*</span><span class="token number">180</span><span class="token operator">/</span><span class="token number">3.1416</span>df<span class="token punctuation">[</span><span class="token string">'arctan_20'</span><span class="token punctuation">]</span> <span class="token operator">=</span> np<span class="token punctuation">.</span>arctan<span class="token punctuation">(</span><span class="token punctuation">(</span>df<span class="token punctuation">[</span><span class="token string">'mean_20'</span><span class="token punctuation">]</span><span class="token operator">/</span>df<span class="token punctuation">[</span><span class="token string">'mean_20'</span><span class="token punctuation">]</span><span class="token punctuation">.</span>shift<span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">)</span><span class="token operator">-</span><span class="token number">1</span><span class="token punctuation">)</span><span class="token operator">*</span><span class="token number">100</span><span class="token punctuation">)</span><span class="token operator">*</span><span class="token number">180</span><span class="token operator">/</span><span class="token number">3.1416</span>df<span class="token punctuation">[</span><span class="token string">'arctan_60'</span><span class="token punctuation">]</span> <span class="token operator">=</span> np<span class="token punctuation">.</span>arctan<span class="token punctuation">(</span><span class="token punctuation">(</span>df<span class="token punctuation">[</span><span class="token string">'mean_60'</span><span class="token punctuation">]</span><span class="token operator">/</span>df<span class="token punctuation">[</span><span class="token string">'mean_60'</span><span class="token punctuation">]</span><span class="token punctuation">.</span>shift<span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">)</span><span class="token operator">-</span><span class="token number">1</span><span class="token punctuation">)</span><span class="token operator">*</span><span class="token number">100</span><span class="token punctuation">)</span><span class="token operator">*</span><span class="token number">180</span><span class="token operator">/</span><span class="token number">3.1416</span>df<span class="token punctuation">[</span><span class="token string">'arctan_120'</span><span class="token punctuation">]</span> <span class="token operator">=</span> np<span class="token punctuation">.</span>arctan<span class="token punctuation">(</span><span class="token punctuation">(</span>df<span class="token punctuation">[</span><span class="token string">'mean_120'</span><span class="token punctuation">]</span><span class="token operator">/</span>df<span class="token punctuation">[</span><span class="token string">'mean_120'</span><span class="token punctuation">]</span><span class="token punctuation">.</span>shift<span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">)</span><span class="token operator">-</span><span class="token number">1</span><span class="token punctuation">)</span><span class="token operator">*</span><span class="token number">100</span><span class="token punctuation">)</span><span class="token operator">*</span><span class="token number">180</span><span class="token operator">/</span><span class="token number">3.1416</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span></span></code></pre><h4 id="计算振幅"><a href="#计算振幅" class="headerlink" title="计算振幅"></a>计算振幅</h4><pre class="line-numbers language-python" data-language="python"><code class="language-python">df<span class="token punctuation">[</span><span class="token string">'max_30'</span><span class="token punctuation">]</span> <span class="token operator">=</span> df<span class="token punctuation">[</span><span class="token string">'high'</span><span class="token punctuation">]</span><span class="token punctuation">.</span>rolling<span class="token punctuation">(</span><span class="token number">30</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token builtin">max</span><span class="token punctuation">(</span><span class="token punctuation">)</span>df<span class="token punctuation">[</span><span class="token string">'min_30'</span><span class="token punctuation">]</span> <span class="token operator">=</span> df<span class="token punctuation">[</span><span class="token string">'low'</span><span class="token punctuation">]</span><span class="token punctuation">.</span>rolling<span class="token punctuation">(</span><span class="token number">30</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token builtin">min</span><span class="token punctuation">(</span><span class="token punctuation">)</span>df<span class="token punctuation">[</span><span class="token string">'daily_30'</span><span class="token punctuation">]</span> <span class="token operator">=</span> df<span class="token punctuation">[</span><span class="token string">'max_30'</span><span class="token punctuation">]</span><span class="token operator">/</span>df<span class="token punctuation">[</span><span class="token string">'min_30'</span><span class="token punctuation">]</span><span class="token operator">-</span><span class="token number">1</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span></span></code></pre><h4 id="获取指数成分股股票代码"><a href="#获取指数成分股股票代码" class="headerlink" title="获取指数成分股股票代码"></a>获取指数成分股股票代码</h4><pre class="line-numbers language-python" data-language="python"><code class="language-python">date<span class="token operator">=</span><span class="token string">'2017-05-23'</span>df <span class="token operator">=</span> D<span class="token punctuation">.</span>history_data<span class="token punctuation">(</span>D<span class="token punctuation">.</span>instruments<span class="token punctuation">(</span>date<span class="token punctuation">,</span>date<span class="token punctuation">)</span><span class="token punctuation">,</span>date<span class="token punctuation">,</span>date<span class="token punctuation">,</span>fields<span class="token operator">=</span><span class="token punctuation">[</span><span class="token string">'in_csi300'</span><span class="token punctuation">]</span><span class="token punctuation">)</span>hs300 <span class="token operator">=</span> <span class="token builtin">set</span><span class="token punctuation">(</span>df<span class="token punctuation">[</span>df<span class="token punctuation">[</span><span class="token string">'in_csi300'</span><span class="token punctuation">]</span><span class="token operator">==</span><span class="token number">1</span><span class="token punctuation">]</span><span class="token punctuation">[</span><span class="token string">'instrument'</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span></span></code></pre><h4 id="禁用缓存"><a href="#禁用缓存" class="headerlink" title="禁用缓存"></a>禁用缓存</h4><pre class="line-numbers language-python" data-language="python"><code class="language-python">m1 <span class="token operator">=</span> M<span class="token punctuation">.</span>cached<span class="token punctuation">.</span>v2<span class="token punctuation">(</span>run<span class="token operator">=</span>foo1<span class="token punctuation">,</span>kwargs<span class="token operator">=</span><span class="token builtin">dict</span><span class="token punctuation">(</span>name<span class="token operator">=</span><span class="token string">'quant'</span><span class="token punctuation">)</span><span class="token punctuation">,</span>m_cached<span class="token operator">=</span><span class="token boolean">False</span><span class="token punctuation">)</span><span aria-hidden="true" class="line-numbers-rows"><span></span></span></code></pre><h4 id="获取板块名称列表"><a href="#获取板块名称列表" class="headerlink" title="获取板块名称列表"></a>获取板块名称列表</h4><pre class="line-numbers language-python" data-language="python"><code class="language-python">instruments <span class="token operator">=</span> D<span class="token punctuation">.</span>instruments<span class="token punctuation">(</span><span class="token punctuation">)</span>df <span class="token operator">=</span> D<span class="token punctuation">.</span>history_data<span class="token punctuation">(</span>instruments<span class="token punctuation">,</span>start_date<span class="token operator">=</span><span class="token string">'2017-05-19'</span><span class="token punctuation">,</span>end_date<span class="token operator">=</span><span class="token string">'2017-05-19'</span><span class="token punctuation">,</span>fields<span class="token operator">=</span><span class="token punctuation">[</span><span class="token string">'concept'</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token builtin">set</span><span class="token punctuation">(</span><span class="token punctuation">[</span>y <span class="token keyword">for</span> x <span class="token keyword">in</span> df<span class="token punctuation">[</span><span class="token string">'concept'</span><span class="token punctuation">]</span> <span class="token keyword">if</span> x <span class="token keyword">for</span> y <span class="token keyword">in</span> x<span class="token punctuation">.</span>split<span class="token punctuation">(</span><span class="token string">';'</span><span class="token punctuation">)</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span></span></code></pre><h4 id="获取指定板块数据"><a href="#获取指定板块数据" class="headerlink" title="获取指定板块数据"></a>获取指定板块数据</h4><pre class="line-numbers language-python" data-language="python"><code class="language-python">instruments <span class="token operator">=</span> D<span class="token punctuation">.</span>instruments<span class="token punctuation">(</span><span class="token punctuation">)</span>df <span class="token operator">=</span> D<span class="token punctuation">.</span>history_data<span class="token punctuation">(</span>instruments<span class="token punctuation">,</span>start_date<span class="token operator">=</span><span class="token string">'2017-05-19'</span><span class="token punctuation">,</span>end_date<span class="token operator">=</span><span class="token string">'2017-05-19'</span><span class="token punctuation">,</span>fields<span class="token operator">=</span><span class="token punctuation">[</span><span class="token string">'concept'</span><span class="token punctuation">]</span><span class="token punctuation">)</span>df<span class="token punctuation">[</span>df<span class="token punctuation">[</span><span class="token string">'concept'</span><span class="token punctuation">]</span><span class="token punctuation">.</span><span class="token builtin">apply</span><span class="token punctuation">(</span><span class="token keyword">lambda</span> x<span class="token punctuation">:</span><span class="token string">'智能家居'</span> <span class="token keyword">in</span> x<span class="token punctuation">.</span>split<span class="token punctuation">(</span><span class="token string">';'</span><span class="token punctuation">)</span> <span class="token keyword">if</span> x <span class="token keyword">else</span> <span class="token boolean">False</span><span class="token punctuation">)</span><span class="token punctuation">]</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span></span></code></pre><h4 id="回测交易"><a href="#回测交易" class="headerlink" title="回测交易"></a>回测交易</h4><pre class="line-numbers language-python" data-language="python"><code class="language-python"><span class="token comment"># 证券池:这里使用所有股票</span>instruments <span class="token operator">=</span> D<span class="token punctuation">.</span>instruments<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token comment"># 起始日期</span>start_date <span class="token operator">=</span> <span class="token string">'2018-06-01'</span><span class="token comment"># 结束日期</span>end_date <span class="token operator">=</span> <span class="token string">'2020-11-24'</span><span class="token comment"># 初始资金</span>capital_base <span class="token operator">=</span> <span class="token number">1000000</span><span class="token comment"># 策略比较参考标准,以沪深300为例</span>benchmark <span class="token operator">=</span> <span class="token string">'000300.INDX'</span><span class="token comment"># 调仓周期(多少个交易日调仓)</span>rebalance_period <span class="token operator">=</span> <span class="token number">1</span>m <span class="token operator">=</span> M<span class="token punctuation">.</span>trade<span class="token punctuation">.</span>v3<span class="token punctuation">(</span> instruments<span class="token operator">=</span>instruments<span class="token punctuation">,</span> start_date<span class="token operator">=</span>start_date<span class="token punctuation">,</span> end_date<span class="token operator">=</span>end_date<span class="token punctuation">,</span> initialize<span class="token operator">=</span>initialize<span class="token punctuation">,</span> handle_data<span class="token operator">=</span>handle_data<span class="token punctuation">,</span> <span class="token comment"># 买入订单以收盘价成交</span> order_price_field_buy<span class="token operator">=</span><span class="token string">'close'</span><span class="token punctuation">,</span> <span class="token comment"># 卖出订单以开盘价成交</span> order_price_field_sell<span class="token operator">=</span><span class="token string">'open'</span><span class="token punctuation">,</span><span class="token comment"># price_type='真实价格',</span> capital_base<span class="token operator">=</span>capital_base<span class="token punctuation">,</span> benchmark<span class="token operator">=</span>benchmark<span class="token punctuation">,</span> <span class="token comment"># 传入数据给回测模块,所有回测函数里用到的数据都要从这里传入,并通过 context.options 使用,否则可能会遇到缓存问题</span> options<span class="token operator">=</span><span class="token punctuation">{</span><span class="token string">'selected_data'</span><span class="token punctuation">:</span> selected_data<span class="token punctuation">,</span> <span class="token string">'rebalance_period'</span><span class="token punctuation">:</span> rebalance_period<span class="token punctuation">}</span><span class="token punctuation">)</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre>]]></content>
<categories>
<category> 技术文档 </category>
</categories>
<tags>
<tag> Bigquant </tag>
</tags>
</entry>
<entry>
<title>画展</title>
<link href="/2021/06/25/hua-zhan/"/>
<url>/2021/06/25/hua-zhan/</url>
<content type="html"><![CDATA[<h1 id="画展"><a href="#画展" class="headerlink" title="画展"></a>画展</h1><hr><p>小白画手偶尔心血来潮的作品,时间按降序排序,喜欢的可以自取~</p><h2 id="2021年7月1日"><a href="#2021年7月1日" class="headerlink" title="2021年7月1日"></a>2021年7月1日</h2><p><img src="/2021/06/25/hua-zhan/lucky.jpg" alt="百事可爱"></p><h2 id="2021年6月30日"><a href="#2021年6月30日" class="headerlink" title="2021年6月30日"></a>2021年6月30日</h2><p><img src="https://i.loli.net/2021/07/02/Eh1qWPnbMjGacfx.jpg" alt="彩虹"></p><h2 id="2021年6月20日"><a href="#2021年6月20日" class="headerlink" title="2021年6月20日"></a>2021年6月20日</h2><p><img src="https://i.loli.net/2021/07/02/oV7bLAMy34WGcRx.jpg" alt="干杯!🍻"></p><h2 id="2021年6月12日"><a href="#2021年6月12日" class="headerlink" title="2021年6月12日"></a>2021年6月12日</h2><p><img src="https://i.loli.net/2021/07/02/PT7e54YQdyoql3t.jpg" alt="万事顺“荔”"></p><h2 id="2021年5月23日"><a href="#2021年5月23日" class="headerlink" title="2021年5月23日"></a>2021年5月23日</h2><p><img src="https://i.loli.net/2021/06/25/SXfycNaFwrM17UP.jpg" alt="スイカ!🍉"></p><h2 id="2021年4月15日"><a href="#2021年4月15日" class="headerlink" title="2021年4月15日"></a>2021年4月15日</h2><p><img src="https://i.loli.net/2021/07/02/GOp8snXZmzVQJM1.jpg" alt="午后"></p><h2 id="2021年2月10日"><a href="#2021年2月10日" class="headerlink" title="2021年2月10日"></a>2021年2月10日</h2><p><img src="https://i.loli.net/2021/07/02/EtmoKp1bZqaw9vY.jpg" alt="冰淇淋!🍦"></p><h2 id="2020年12月1日"><a href="#2020年12月1日" class="headerlink" title="2020年12月1日"></a>2020年12月1日</h2><p><img src="https://i.loli.net/2021/07/02/lxjA3zuOaJi41W5.jpg" alt="月亮!🌙"></p>]]></content>
<tags>
<tag> 画 </tag>
</tags>
</entry>
<entry>
<title>Android平台整合H5WebApp,集成企业微信SDK</title>
<link href="/2021/01/22/android-ping-tai-zheng-he-h5webapp-ji-cheng-qi-ye-wei-xin-sdk/"/>
<url>/2021/01/22/android-ping-tai-zheng-he-h5webapp-ji-cheng-qi-ye-wei-xin-sdk/</url>
<content type="html"><![CDATA[<h1 id="Android平台整合H5WebApp,集成企业微信SDK"><a href="#Android平台整合H5WebApp,集成企业微信SDK" class="headerlink" title="Android平台整合H5WebApp,集成企业微信SDK"></a>Android平台整合H5WebApp,集成企业微信SDK</h1><h3 id="一、整合前准备"><a href="#一、整合前准备" class="headerlink" title="一、整合前准备"></a>一、整合前准备</h3><ol><li><p>下载<a href="https://nativesupport.dcloud.net.cn/AppDocs/download/android">AndroidSDK</a></p></li><li><p><a href="https://work.weixin.qq.com/api/doc/90000/90138/91074">企业微信移动端SDK</a>资源下载,将签名生成工具安装在手机端,之后在获取企业微信登录权限时需要用到。</p><blockquote><p>使用企业微信登录、分享功能需要用到文件如下。<br>点击下载<a href="http://open.work.weixin.qq.com/wwopen/downloadfile/wwapi.zip">Android开发工具包集合</a> 。每个第三方应用必须要导入该SDK库,用于实现与企业微信的通信<br>点击下载 <a href="http://dldir1.qq.com/qqcontacts/Gen_Signature_Android.apk">签名生成工具</a>。安装此工具,根据指引生成的应用签名字符串并填写在应用管理平台上,未填写或者填写错误将导致接口无法使用。<br>点击下载<a href="http://dldir1.qq.com/qqcontacts/apitest_2.zip">接口使用Demo</a>。开发者可以参考Demo中的接口使用方式进行开发。</p></blockquote></li><li><p>必要开发软件自行下载</p><ul><li>Android studio</li><li>Hbuilder</li></ul></li></ol><h3 id="二、导入AndroidDemo"><a href="#二、导入AndroidDemo" class="headerlink" title="二、导入AndroidDemo"></a>二、导入AndroidDemo</h3><ol><li><p>sdk目录 </p><p><img src="https://i.loli.net/2021/01/22/9bTciu8DAyv1kNS.png"> </p></li><li><p>将HBuilder-Hello导入Android Studio,在导入过程中可能会出现各种奇奇怪怪的问题,请自行百度解决,在这里提供一些可能会出现问题的解决方法</p><ul><li><p><strong>Error:Connection timed out: connect. If you are behind an HTTP proxy, please configure the proxy settings either in IDE or Gradle.</strong></p><p>由于网络原因,无法下载gradle,解决办法:</p><p>在项目目录,“<em>\gradle\wrapper\gradle-wrapper.properties</em>”中查看当前项目所需要的gradle版本号,如下所示:gradle的版本为gradle-6.5-all.zip</p><p><code>distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip</code></p><p>在<a href="https://www.androiddevtools.cn/">androiddevtools</a>中下载对应的gradle包,下载好之后直接丢进”<em>C:\Users\zora\.gradle\wrapper\dists\gradle-6.5-all\<随机生成的字符串></em>“里面,重新运行Android Studio</p></li><li><p><strong>Error:Cause: failed to find target with hash string ‘android-23’</strong></p><p>缺少对应的SDK文件,解决方法:在Android Studio中打开”File>Settings“,搜索sdk,下载对应的sdk文件,重新rebuild项目。</p></li></ul></li></ol><h3 id="三、整合webApp"><a href="#三、整合webApp" class="headerlink" title="三、整合webApp"></a>三、整合webApp</h3><p>官方离线打包参考链接:<a href="https://nativesupport.dcloud.net.cn/AppDocs/usesdk/android">Android离线打包</a></p><ol><li><p> 打包H5+APP</p><p>在HBuilder中,打包成本地资源,将资源文件放在HBuilder-Hello的”<em>\app\src\main\assets\apps<webApp对应id,在manifest.json中查看>\www</em>“中,如果没有该文件夹则创建一个www空文件夹。</p><p><img src="https://i.loli.net/2021/01/22/YTknLBd324DbVgN.png"> <img src="https://i.loli.net/2021/01/22/sxlPiqzvEt2OR1d.png"></p></li><li><p>修改dcloud_control.xml中的appid,appid就是在manifest.json文件中定义的id,<strong>与apps下的文件夹同名</strong>。</p><pre class="line-numbers language-xml" data-language="xml"><code class="language-xml"><span class="token tag"><span class="token tag"><span class="token punctuation"><</span>hbuilder</span><span class="token punctuation">></span></span><span class="token tag"><span class="token tag"><span class="token punctuation"><</span>apps</span><span class="token punctuation">></span></span> <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>app</span> <span class="token attr-name">appid</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>H******E<span class="token punctuation">"</span></span> <span class="token attr-name">appver</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span><span class="token punctuation">"</span></span><span class="token punctuation">/></span></span><span class="token tag"><span class="token tag"><span class="token punctuation"></</span>apps</span><span class="token punctuation">></span></span><span class="token tag"><span class="token tag"><span class="token punctuation"></</span>hbuilder</span><span class="token punctuation">></span></span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span></span></code></pre></li><li><p>运行项目</p><p><img src="https://i.loli.net/2021/01/22/GdxfWMEgAlmUY6j.png"></p></li></ol><h3 id="四、整合企业微信SDK"><a href="#四、整合企业微信SDK" class="headerlink" title="四、整合企业微信SDK"></a>四、整合企业微信SDK</h3><p>官方sdk整合链接:<a href="https://work.weixin.qq.com/api/doc/90000/90136/91194">Android接入指南</a></p><ol><li><p>在下载好的企业微信Demo中,将”<em>\apitest_2\apitest\app\libs</em>“中的libwwsdk.jar复制到HBuilder-Hello的libs文件夹中,这样就成功的引入了企业微信sdk</p></li><li><p>进行代码开发,官方给出的代码对与纯Android原生开发的应用是没有问题的!但是,我们是整合了webAPP进行的混合开发!<span class="github-emoji"><span>😢</span><img src="https://github.githubassets.com/images/icons/emoji/unicode/1f622.png?v8" aria-hidden="true" onerror="this.parent.classList.add('github-emoji-fallback')"></span></p><p>这里我找遍全网都没找到解决方法,可能是企业微信集成的需求不大?踩了很多坑,在看了一天的源码之后,摸索出一条解决办法,因为AndroidSDK中是提供了微信、qq等第三方登录接口的,所以我依葫芦画瓢,增加了一个企业微信的登录接口。可以参考<a href="https://ask.dcloud.net.cn/article/66">Android平台第三方插件开发指导</a></p><ul><li><p>在”<em>java\io\dcloud\HelloH5\wxapi</em>“中新建类<strong>QyWeiXinOAuthService.java</strong>继承<strong>BaseOAuthService</strong>,具体代码如下</p><pre class="line-numbers language-java" data-language="java"><code class="language-java"><span class="token keyword">package</span> <span class="token namespace">io<span class="token punctuation">.</span>dcloud<span class="token punctuation">.</span></span><span class="token class-name">HelloH5</span><span class="token punctuation">.</span>wxapi<span class="token punctuation">;</span><span class="token keyword">import</span> <span class="token namespace">android<span class="token punctuation">.</span>content<span class="token punctuation">.</span></span><span class="token class-name">Context</span><span class="token punctuation">;</span><span class="token keyword">import</span> <span class="token namespace">android<span class="token punctuation">.</span>text<span class="token punctuation">.</span></span><span class="token class-name">TextUtils</span><span class="token punctuation">;</span><span class="token keyword">import</span> <span class="token namespace">android<span class="token punctuation">.</span>widget<span class="token punctuation">.</span></span><span class="token class-name">Toast</span><span class="token punctuation">;</span><span class="token keyword">import</span> <span class="token namespace">com<span class="token punctuation">.</span>tencent<span class="token punctuation">.</span>wework<span class="token punctuation">.</span>api<span class="token punctuation">.</span></span>IWWAPI<span class="token punctuation">;</span><span class="token keyword">import</span> <span class="token namespace">com<span class="token punctuation">.</span>tencent<span class="token punctuation">.</span>wework<span class="token punctuation">.</span>api<span class="token punctuation">.</span></span><span class="token class-name">IWWAPIEventHandler</span><span class="token punctuation">;</span><span class="token keyword">import</span> <span class="token namespace">com<span class="token punctuation">.</span>tencent<span class="token punctuation">.</span>wework<span class="token punctuation">.</span>api<span class="token punctuation">.</span></span><span class="token class-name">WWAPIFactory</span><span class="token punctuation">;</span><span class="token keyword">import</span> <span class="token namespace">com<span class="token punctuation">.</span>tencent<span class="token punctuation">.</span>wework<span class="token punctuation">.</span>api<span class="token punctuation">.</span>model<span class="token punctuation">.</span></span><span class="token class-name">BaseMessage</span><span class="token punctuation">;</span><span class="token keyword">import</span> <span class="token namespace">com<span class="token punctuation">.</span>tencent<span class="token punctuation">.</span>wework<span class="token punctuation">.</span>api<span class="token punctuation">.</span>model<span class="token punctuation">.</span></span><span class="token class-name">WWAuthMessage</span><span class="token punctuation">;</span><span class="token keyword">import</span> <span class="token namespace">org<span class="token punctuation">.</span>json<span class="token punctuation">.</span></span><span class="token class-name">JSONArray</span><span class="token punctuation">;</span><span class="token keyword">import</span> <span class="token namespace">org<span class="token punctuation">.</span>json<span class="token punctuation">.</span></span><span class="token class-name">JSONException</span><span class="token punctuation">;</span><span class="token keyword">import</span> <span class="token namespace">org<span class="token punctuation">.</span>json<span class="token punctuation">.</span></span><span class="token class-name">JSONObject</span><span class="token punctuation">;</span><span class="token keyword">import</span> <span class="token namespace">io<span class="token punctuation">.</span>dcloud<span class="token punctuation">.</span>common<span class="token punctuation">.</span></span><span class="token class-name">DHInterface</span><span class="token punctuation">.</span><span class="token class-name">IWebview</span><span class="token punctuation">;</span><span class="token keyword">import</span> <span class="token namespace">io<span class="token punctuation">.</span>dcloud<span class="token punctuation">.</span>common<span class="token punctuation">.</span>adapter<span class="token punctuation">.</span>util<span class="token punctuation">.</span></span><span class="token class-name">AndroidResources</span><span class="token punctuation">;</span><span class="token keyword">import</span> <span class="token namespace">io<span class="token punctuation">.</span>dcloud<span class="token punctuation">.</span>common<span class="token punctuation">.</span>adapter<span class="token punctuation">.</span>util<span class="token punctuation">.</span></span><span class="token class-name">Logger</span><span class="token punctuation">;</span><span class="token keyword">import</span> <span class="token namespace">io<span class="token punctuation">.</span>dcloud<span class="token punctuation">.</span>common<span class="token punctuation">.</span>adapter<span class="token punctuation">.</span>util<span class="token punctuation">.</span></span><span class="token class-name">PlatformUtil</span><span class="token punctuation">;</span><span class="token keyword">import</span> <span class="token namespace">io<span class="token punctuation">.</span>dcloud<span class="token punctuation">.</span>common<span class="token punctuation">.</span>constant<span class="token punctuation">.</span></span><span class="token class-name">DOMException</span><span class="token punctuation">;</span><span class="token keyword">import</span> <span class="token namespace">io<span class="token punctuation">.</span>dcloud<span class="token punctuation">.</span>common<span class="token punctuation">.</span>util<span class="token punctuation">.</span></span><span class="token class-name">JSUtil</span><span class="token punctuation">;</span><span class="token keyword">import</span> <span class="token namespace">io<span class="token punctuation">.</span>dcloud<span class="token punctuation">.</span>common<span class="token punctuation">.</span>util<span class="token punctuation">.</span></span><span class="token class-name">StringUtil</span><span class="token punctuation">;</span><span class="token keyword">import</span> <span class="token namespace">io<span class="token punctuation">.</span>dcloud<span class="token punctuation">.</span>common<span class="token punctuation">.</span>util<span class="token punctuation">.</span></span><span class="token class-name">ThreadPool</span><span class="token punctuation">;</span><span class="token keyword">import</span> <span class="token namespace">io<span class="token punctuation">.</span>dcloud<span class="token punctuation">.</span>feature<span class="token punctuation">.</span>oauth<span class="token punctuation">.</span></span><span class="token class-name">BaseOAuthService</span><span class="token punctuation">;</span><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">QyWeiXinOAuthService</span> <span class="token keyword">extends</span> <span class="token class-name">BaseOAuthService</span> <span class="token punctuation">{</span> <span class="token keyword">private</span> <span class="token class-name">IWWAPI</span> iwwapi<span class="token punctuation">;</span><span class="token comment">//企业微信api</span> <span class="token keyword">private</span> <span class="token class-name">String</span> code<span class="token punctuation">;</span> <span class="token keyword">private</span> <span class="token keyword">static</span> <span class="token keyword">final</span> <span class="token class-name">String</span> TAG <span class="token operator">=</span> <span class="token string">"QyWeiXinOAuthService"</span><span class="token punctuation">;</span> <span class="token keyword">private</span> <span class="token keyword">static</span> <span class="token keyword">final</span> <span class="token class-name">String</span> SCHEMA <span class="token operator">=</span> <span class="token string">"wwauth***********000006"</span><span class="token punctuation">;</span><span class="token comment">//企业微信授权登录中的SCHEMA,获取方法请参考步骤六</span> <span class="token keyword">protected</span> <span class="token keyword">static</span> <span class="token class-name">String</span> appId <span class="token operator">=</span> <span class="token keyword">null</span><span class="token punctuation">;</span> <span class="token keyword">protected</span> <span class="token keyword">static</span> <span class="token class-name">String</span> agentId <span class="token operator">=</span> <span class="token keyword">null</span><span class="token punctuation">;</span> <span class="token keyword">private</span> <span class="token keyword">boolean</span> isAuth <span class="token operator">=</span> <span class="token boolean">false</span><span class="token punctuation">;</span> <span class="token keyword">public</span> <span class="token class-name">QyWeiXinOAuthService</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span> <span class="token punctuation">}</span> <span class="token keyword">public</span> <span class="token keyword">boolean</span> <span class="token function">hasFullConfigData</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token keyword">return</span> <span class="token operator">!</span><span class="token class-name">TextUtils</span><span class="token punctuation">.</span><span class="token function">isEmpty</span><span class="token punctuation">(</span>appId<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token punctuation">}</span> <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">initAuthOptions</span><span class="token punctuation">(</span><span class="token class-name">JSONObject</span> mLoginOptions<span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token keyword">if</span> <span class="token punctuation">(</span>mLoginOptions <span class="token operator">!=</span> <span class="token keyword">null</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> appId <span class="token operator">=</span> mLoginOptions<span class="token punctuation">.</span><span class="token function">optString</span><span class="token punctuation">(</span><span class="token string">"appid"</span><span class="token punctuation">,</span> appId<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token class-name">Logger</span><span class="token punctuation">.</span><span class="token function">e</span><span class="token punctuation">(</span><span class="token string">"QyWeiXinOAuthService"</span><span class="token punctuation">,</span> <span class="token string">"initAuthOptions: appId"</span> <span class="token operator">+</span> appId<span class="token punctuation">)</span><span class="token punctuation">;</span> agentId <span class="token operator">=</span> mLoginOptions<span class="token punctuation">.</span><span class="token function">optString</span><span class="token punctuation">(</span><span class="token string">"agentId"</span><span class="token punctuation">,</span> agentId<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">initMetaData</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> appId <span class="token operator">=</span> <span class="token class-name">AndroidResources</span><span class="token punctuation">.</span><span class="token function">getMetaValue</span><span class="token punctuation">(</span><span class="token string">"QYWX_APPID"</span><span class="token punctuation">)</span><span class="token punctuation">;</span> agentId <span class="token operator">=</span> <span class="token class-name">AndroidResources</span><span class="token punctuation">.</span><span class="token function">getMetaValue</span><span class="token punctuation">(</span><span class="token string">"QYWX_AGENTID"</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token punctuation">}</span> <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">init</span><span class="token punctuation">(</span><span class="token class-name">Context</span> context<span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token keyword">super</span><span class="token punctuation">.</span><span class="token function">init</span><span class="token punctuation">(</span>context<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token keyword">this</span><span class="token punctuation">.</span>id <span class="token operator">=</span> <span class="token string">"qyweixin"</span><span class="token punctuation">;</span> <span class="token keyword">this</span><span class="token punctuation">.</span>description <span class="token operator">=</span> <span class="token string">"企业微信"</span><span class="token punctuation">;</span> <span class="token punctuation">}</span> <span class="token keyword">private</span> <span class="token keyword">void</span> <span class="token function">onLoginCallBack</span><span class="token punctuation">(</span><span class="token class-name">IWebview</span> pWebViewImpl<span class="token punctuation">,</span> <span class="token class-name">String</span> pCallbackId<span class="token punctuation">,</span> <span class="token keyword">int</span> code<span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token keyword">boolean</span> suc <span class="token operator">=</span> <span class="token boolean">false</span><span class="token punctuation">;</span> <span class="token class-name">String</span> errorMsg <span class="token operator">=</span> <span class="token string">"send"</span><span class="token punctuation">;</span> <span class="token keyword">if</span> <span class="token punctuation">(</span>code <span class="token operator">==</span> <span class="token class-name">WWAuthMessage</span><span class="token punctuation">.</span>ERR_OK<span class="token punctuation">)</span> <span class="token punctuation">{</span> suc <span class="token operator">=</span> <span class="token boolean">true</span><span class="token punctuation">;</span> <span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token keyword">if</span> <span class="token punctuation">(</span>code <span class="token operator">==</span> <span class="token class-name">WWAuthMessage</span><span class="token punctuation">.</span>ERR_FAIL<span class="token punctuation">)</span> <span class="token punctuation">{</span> errorMsg <span class="token operator">=</span> <span class="token string">"登录失败"</span><span class="token punctuation">;</span> <span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token keyword">if</span> <span class="token punctuation">(</span>code <span class="token operator">==</span> <span class="token class-name">WWAuthMessage</span><span class="token punctuation">.</span>ERR_CANCEL<span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">onLoginFinished</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">getErrorJsonbject</span><span class="token punctuation">(</span><span class="token operator">-</span><span class="token number">2</span><span class="token punctuation">,</span> <span class="token string">"用户取消"</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token boolean">false</span><span class="token punctuation">,</span> pWebViewImpl<span class="token punctuation">,</span> pCallbackId<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token keyword">return</span><span class="token punctuation">;</span> <span class="token punctuation">}</span> <span class="token keyword">if</span> <span class="token punctuation">(</span>suc<span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token class-name">JSUtil</span><span class="token punctuation">.</span><span class="token function">execCallback</span><span class="token punctuation">(</span>pWebViewImpl<span class="token punctuation">,</span> pCallbackId<span class="token punctuation">,</span> <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">makeResultJSONObject</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token class-name">JSUtil</span><span class="token punctuation">.</span>OK<span class="token punctuation">,</span> <span class="token boolean">false</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token punctuation">{</span> <span class="token class-name">String</span> msg <span class="token operator">=</span> <span class="token class-name">DOMException</span><span class="token punctuation">.</span><span class="token function">toJSON</span><span class="token punctuation">(</span><span class="token operator">-</span><span class="token number">100</span><span class="token punctuation">,</span> errorMsg<span class="token punctuation">,</span> code<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token class-name">JSUtil</span><span class="token punctuation">.</span><span class="token function">execCallback</span><span class="token punctuation">(</span>pWebViewImpl<span class="token punctuation">,</span> pCallbackId<span class="token punctuation">,</span> msg<span class="token punctuation">,</span> <span class="token class-name">JSUtil</span><span class="token punctuation">.</span>ERROR<span class="token punctuation">,</span> <span class="token boolean">true</span><span class="token punctuation">,</span> <span class="token boolean">false</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">login</span><span class="token punctuation">(</span><span class="token class-name">IWebview</span> pWebViewImpl<span class="token punctuation">,</span> <span class="token class-name">JSONArray</span> pJsArgs<span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token keyword">super</span><span class="token punctuation">.</span><span class="token function">login</span><span class="token punctuation">(</span>pWebViewImpl<span class="token punctuation">,</span> pJsArgs<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token operator">!</span><span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">hasGeneralError</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">.</span>mLoginWebViewImpl<span class="token punctuation">,</span> <span class="token keyword">this</span><span class="token punctuation">.</span>mLoginCallbackId<span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token operator">!</span><span class="token class-name">PlatformUtil</span><span class="token punctuation">.</span><span class="token function">isAppInstalled</span><span class="token punctuation">(</span>pWebViewImpl<span class="token punctuation">.</span><span class="token function">getContext</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token string">"com.tencent.wework"</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token class-name">String</span> msg <span class="token operator">=</span> <span class="token class-name">StringUtil</span><span class="token punctuation">.</span><span class="token function">format</span><span class="token punctuation">(</span><span class="token string">"{code:%d,message:'%s'}"</span><span class="token punctuation">,</span> <span class="token keyword">new</span> <span class="token class-name">Object</span><span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">{</span><span class="token operator">-</span><span class="token number">8</span><span class="token punctuation">,</span> <span class="token class-name">DOMException</span><span class="token punctuation">.</span><span class="token function">toString</span><span class="token punctuation">(</span><span class="token string">"客户端未安装"</span><span class="token punctuation">)</span><span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token class-name">JSUtil</span><span class="token punctuation">.</span><span class="token function">execCallback</span><span class="token punctuation">(</span>pWebViewImpl<span class="token punctuation">,</span> <span class="token keyword">this</span><span class="token punctuation">.</span>mLoginCallbackId<span class="token punctuation">,</span> msg<span class="token punctuation">,</span> <span class="token class-name">JSUtil</span><span class="token punctuation">.</span>ERROR<span class="token punctuation">,</span> <span class="token boolean">true</span><span class="token punctuation">,</span> <span class="token boolean">false</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token punctuation">{</span> <span class="token class-name">ThreadPool</span><span class="token punctuation">.</span><span class="token function">self</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">addThreadTask</span><span class="token punctuation">(</span><span class="token keyword">new</span> <span class="token class-name">Runnable</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">run</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token class-name">QyWeiXinOAuthService</span><span class="token punctuation">.</span><span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">loginInThread</span><span class="token punctuation">(</span><span class="token class-name">QyWeiXinOAuthService</span><span class="token punctuation">.</span><span class="token keyword">this</span><span class="token punctuation">.</span>mLoginWebViewImpl<span class="token punctuation">,</span> <span class="token class-name">QyWeiXinOAuthService</span><span class="token punctuation">.</span><span class="token keyword">this</span><span class="token punctuation">.</span>mLoginCallbackId<span class="token punctuation">,</span> <span class="token class-name">QyWeiXinOAuthService</span><span class="token punctuation">.</span><span class="token keyword">this</span><span class="token punctuation">.</span>mLoginOptions<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">authorize</span><span class="token punctuation">(</span><span class="token class-name">IWebview</span> pwebview<span class="token punctuation">,</span> <span class="token class-name">JSONArray</span> pJsArgs<span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token keyword">super</span><span class="token punctuation">.</span><span class="token function">authorize</span><span class="token punctuation">(</span>pwebview<span class="token punctuation">,</span> pJsArgs<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token class-name">String</span> msg<span class="token punctuation">;</span> <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token class-name">TextUtils</span><span class="token punctuation">.</span><span class="token function">isEmpty</span><span class="token punctuation">(</span>appId<span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> msg <span class="token operator">=</span> <span class="token class-name">StringUtil</span><span class="token punctuation">.</span><span class="token function">format</span><span class="token punctuation">(</span><span class="token string">"{code:%d,message:'%s'}"</span><span class="token punctuation">,</span> <span class="token keyword">new</span> <span class="token class-name">Object</span><span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">{</span><span class="token operator">-</span><span class="token number">7</span><span class="token punctuation">,</span> <span class="token class-name">DOMException</span><span class="token punctuation">.</span><span class="token function">toString</span><span class="token punctuation">(</span><span class="token string">"业务参数配置缺失"</span><span class="token punctuation">)</span><span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token class-name">JSUtil</span><span class="token punctuation">.</span><span class="token function">execCallback</span><span class="token punctuation">(</span>pwebview<span class="token punctuation">,</span> <span class="token keyword">this</span><span class="token punctuation">.</span>mAuthCallbackId<span class="token punctuation">,</span> msg<span class="token punctuation">,</span> <span class="token class-name">JSUtil</span><span class="token punctuation">.</span>ERROR<span class="token punctuation">,</span> <span class="token boolean">true</span><span class="token punctuation">,</span> <span class="token boolean">false</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token operator">!</span><span class="token class-name">PlatformUtil</span><span class="token punctuation">.</span><span class="token function">isAppInstalled</span><span class="token punctuation">(</span>pwebview<span class="token punctuation">.</span><span class="token function">getContext</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token string">"com.tencent.wework"</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> msg <span class="token operator">=</span> <span class="token class-name">StringUtil</span><span class="token punctuation">.</span><span class="token function">format</span><span class="token punctuation">(</span><span class="token string">"{code:%d,message:'%s'}"</span><span class="token punctuation">,</span> <span class="token keyword">new</span> <span class="token class-name">Object</span><span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">{</span><span class="token operator">-</span><span class="token number">8</span><span class="token punctuation">,</span> <span class="token class-name">DOMException</span><span class="token punctuation">.</span><span class="token function">toString</span><span class="token punctuation">(</span><span class="token string">"客户端未安装"</span><span class="token punctuation">)</span><span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token class-name">JSUtil</span><span class="token punctuation">.</span><span class="token function">execCallback</span><span class="token punctuation">(</span>pwebview<span class="token punctuation">,</span> <span class="token keyword">this</span><span class="token punctuation">.</span>mAuthCallbackId<span class="token punctuation">,</span> msg<span class="token punctuation">,</span> <span class="token class-name">JSUtil</span><span class="token punctuation">.</span>ERROR<span class="token punctuation">,</span> <span class="token boolean">true</span><span class="token punctuation">,</span> <span class="token boolean">false</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token punctuation">{</span> <span class="token class-name">ThreadPool</span><span class="token punctuation">.</span><span class="token function">self</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">addThreadTask</span><span class="token punctuation">(</span><span class="token keyword">new</span> <span class="token class-name">Runnable</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">run</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token class-name">QyWeiXinOAuthService</span><span class="token punctuation">.</span><span class="token keyword">this</span><span class="token punctuation">.</span>isAuth <span class="token operator">=</span> <span class="token boolean">true</span><span class="token punctuation">;</span> <span class="token class-name">QyWeiXinOAuthService</span><span class="token punctuation">.</span><span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">loginInThread</span><span class="token punctuation">(</span><span class="token class-name">QyWeiXinOAuthService</span><span class="token punctuation">.</span><span class="token keyword">this</span><span class="token punctuation">.</span>mAuthWebview<span class="token punctuation">,</span> <span class="token class-name">QyWeiXinOAuthService</span><span class="token punctuation">.</span><span class="token keyword">this</span><span class="token punctuation">.</span>mAuthCallbackId<span class="token punctuation">,</span> <span class="token class-name">QyWeiXinOAuthService</span><span class="token punctuation">.</span><span class="token keyword">this</span><span class="token punctuation">.</span>mAuthOptions<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> <span class="token keyword">private</span> <span class="token keyword">void</span> <span class="token function">loginInThread</span><span class="token punctuation">(</span><span class="token keyword">final</span> <span class="token class-name">IWebview</span> pwebview<span class="token punctuation">,</span> <span class="token keyword">final</span> <span class="token class-name">String</span> callbackId<span class="token punctuation">,</span> <span class="token class-name">JSONObject</span> option<span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">.</span>iwwapi <span class="token operator">==</span> <span class="token keyword">null</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token comment">//注册</span> <span class="token keyword">this</span><span class="token punctuation">.</span>iwwapi <span class="token operator">=</span> <span class="token class-name">WWAPIFactory</span><span class="token punctuation">.</span><span class="token function">createWWAPI</span><span class="token punctuation">(</span>pwebview<span class="token punctuation">.</span><span class="token function">getActivity</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token keyword">this</span><span class="token punctuation">.</span>iwwapi<span class="token punctuation">.</span><span class="token function">registerApp</span><span class="token punctuation">(</span>SCHEMA<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token punctuation">}</span> <span class="token keyword">final</span> <span class="token class-name">WWAuthMessage</span><span class="token punctuation">.</span><span class="token class-name">Req</span> req <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">WWAuthMessage</span><span class="token punctuation">.</span><span class="token class-name">Req</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span> req<span class="token punctuation">.</span>sch <span class="token operator">=</span> SCHEMA<span class="token punctuation">;</span> req<span class="token punctuation">.</span>appId <span class="token operator">=</span> appId<span class="token punctuation">;</span> req<span class="token punctuation">.</span>agentId <span class="token operator">=</span> agentId<span class="token punctuation">;</span> req<span class="token punctuation">.</span>state <span class="token operator">=</span> <span class="token string">"combest"</span><span class="token punctuation">;</span><span class="token comment">//授权成功之后的回调函数</span> iwwapi<span class="token punctuation">.</span><span class="token function">sendMessage</span><span class="token punctuation">(</span>req<span class="token punctuation">,</span> <span class="token keyword">new</span> <span class="token class-name">IWWAPIEventHandler</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token annotation punctuation">@Override</span> <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">handleResp</span><span class="token punctuation">(</span><span class="token class-name">BaseMessage</span> resp<span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token keyword">if</span> <span class="token punctuation">(</span>resp <span class="token keyword">instanceof</span> <span class="token class-name">WWAuthMessage</span><span class="token punctuation">.</span><span class="token class-name">Resp</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token class-name">WWAuthMessage</span><span class="token punctuation">.</span><span class="token class-name">Resp</span> rsp <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token class-name">WWAuthMessage</span><span class="token punctuation">.</span><span class="token class-name">Resp</span><span class="token punctuation">)</span> resp<span class="token punctuation">;</span> <span class="token keyword">if</span> <span class="token punctuation">(</span>rsp<span class="token punctuation">.</span>errCode <span class="token operator">==</span> <span class="token class-name">WWAuthMessage</span><span class="token punctuation">.</span>ERR_CANCEL<span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token class-name">Toast</span><span class="token punctuation">.</span><span class="token function">makeText</span><span class="token punctuation">(</span>pwebview<span class="token punctuation">.</span><span class="token function">getContext</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token string">"登陆取消"</span><span class="token punctuation">,</span> <span class="token class-name">Toast</span><span class="token punctuation">.</span>LENGTH_SHORT<span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">show</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token punctuation">}</span><span class="token keyword">else</span> <span class="token keyword">if</span> <span class="token punctuation">(</span>rsp<span class="token punctuation">.</span>errCode <span class="token operator">==</span> <span class="token class-name">WWAuthMessage</span><span class="token punctuation">.</span>ERR_FAIL<span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token class-name">Toast</span><span class="token punctuation">.</span><span class="token function">makeText</span><span class="token punctuation">(</span>pwebview<span class="token punctuation">.</span><span class="token function">getContext</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token string">"登陆失败"</span><span class="token punctuation">,</span> <span class="token class-name">Toast</span><span class="token punctuation">.</span>LENGTH_SHORT<span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">show</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token keyword">if</span> <span class="token punctuation">(</span>rsp<span class="token punctuation">.</span>errCode <span class="token operator">==</span> <span class="token class-name">WWAuthMessage</span><span class="token punctuation">.</span>ERR_OK<span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token class-name">Toast</span><span class="token punctuation">.</span><span class="token function">makeText</span><span class="token punctuation">(</span>pwebview<span class="token punctuation">.</span><span class="token function">getContext</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token string">"登陆成功"</span><span class="token punctuation">,</span> <span class="token class-name">Toast</span><span class="token punctuation">.</span>LENGTH_SHORT<span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">show</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token class-name">QyWeiXinOAuthService</span><span class="token punctuation">.</span><span class="token keyword">this</span><span class="token punctuation">.</span>code <span class="token operator">=</span> rsp<span class="token punctuation">.</span>code<span class="token punctuation">;</span> <span class="token class-name">JSUtil</span><span class="token punctuation">.</span><span class="token function">execCallback</span><span class="token punctuation">(</span>pwebview<span class="token punctuation">,</span> callbackId<span class="token punctuation">,</span> <span class="token class-name">QyWeiXinOAuthService</span><span class="token punctuation">.</span><span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">makeResultJSONObject</span><span class="token punctuation">(</span>rsp<span class="token punctuation">.</span>code<span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token class-name">JSUtil</span><span class="token punctuation">.</span>OK<span class="token punctuation">,</span> <span class="token boolean">false</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token punctuation">}</span> <span class="token keyword">protected</span> <span class="token keyword">void</span> <span class="token function">onLoginFinished</span><span class="token punctuation">(</span><span class="token class-name">JSONObject</span> msg<span class="token punctuation">,</span> <span class="token keyword">boolean</span> suc<span class="token punctuation">,</span> <span class="token class-name">IWebview</span> pwebview<span class="token punctuation">,</span> <span class="token class-name">String</span> callbackId<span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token class-name">JSUtil</span><span class="token punctuation">.</span><span class="token function">execCallback</span><span class="token punctuation">(</span>pwebview<span class="token punctuation">,</span> callbackId<span class="token punctuation">,</span> msg<span class="token punctuation">,</span> suc <span class="token operator">?</span> <span class="token class-name">JSUtil</span><span class="token punctuation">.</span>OK <span class="token operator">:</span> <span class="token class-name">JSUtil</span><span class="token punctuation">.</span>ERROR<span class="token punctuation">,</span> <span class="token boolean">false</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">.</span>isAuth<span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token keyword">this</span><span class="token punctuation">.</span>mAuthWebview <span class="token operator">=</span> <span class="token keyword">null</span><span class="token punctuation">;</span> <span class="token keyword">this</span><span class="token punctuation">.</span>mAuthCallbackId <span class="token operator">=</span> <span class="token keyword">null</span><span class="token punctuation">;</span> <span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token punctuation">{</span> <span class="token keyword">this</span><span class="token punctuation">.</span>mLoginCallbackId <span class="token operator">=</span> <span class="token keyword">null</span><span class="token punctuation">;</span> <span class="token keyword">this</span><span class="token punctuation">.</span>mLoginWebViewImpl <span class="token operator">=</span> <span class="token keyword">null</span><span class="token punctuation">;</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">logout</span><span class="token punctuation">(</span><span class="token class-name">IWebview</span> pWebViewImpl<span class="token punctuation">,</span> <span class="token class-name">JSONArray</span> pJsArgs<span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token keyword">super</span><span class="token punctuation">.</span><span class="token function">logout</span><span class="token punctuation">(</span>pWebViewImpl<span class="token punctuation">,</span> pJsArgs<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token operator">!</span><span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">hasGeneralError</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">.</span>mLogoutWebViewImpl<span class="token punctuation">,</span> <span class="token keyword">this</span><span class="token punctuation">.</span>mLogoutCallbackId<span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">removeToken</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token keyword">this</span><span class="token punctuation">.</span>userInfo <span class="token operator">=</span> <span class="token keyword">null</span><span class="token punctuation">;</span> <span class="token keyword">this</span><span class="token punctuation">.</span>authResult <span class="token operator">=</span> <span class="token keyword">null</span><span class="token punctuation">;</span> <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">onLogoutFinished</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">makeResultJSONObject</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token boolean">true</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token keyword">this</span><span class="token punctuation">.</span>iwwapi <span class="token operator">=</span> <span class="token keyword">null</span><span class="token punctuation">;</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> <span class="token keyword">public</span> <span class="token class-name">JSONObject</span> <span class="token function">makeResultJSONObject</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token class-name">JSONObject</span> sucJSON <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">JSONObject</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token keyword">try</span> <span class="token punctuation">{</span> sucJSON<span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span><span class="token string">"authResult"</span><span class="token punctuation">,</span> <span class="token keyword">this</span><span class="token punctuation">.</span>authResult<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token class-name">String</span> state <span class="token operator">=</span> <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">getValue</span><span class="token punctuation">(</span><span class="token string">"state"</span><span class="token punctuation">)</span><span class="token punctuation">;</span> sucJSON<span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span><span class="token string">"state"</span><span class="token punctuation">,</span> state<span class="token punctuation">)</span><span class="token punctuation">;</span> sucJSON<span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span><span class="token string">"code"</span><span class="token punctuation">,</span> <span class="token keyword">this</span><span class="token punctuation">.</span>code<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token punctuation">}</span> <span class="token keyword">catch</span> <span class="token punctuation">(</span><span class="token class-name">JSONException</span> var3<span class="token punctuation">)</span> <span class="token punctuation">{</span> var3<span class="token punctuation">.</span><span class="token function">printStackTrace</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token punctuation">}</span> <span class="token keyword">return</span> sucJSON<span class="token punctuation">;</span> <span class="token punctuation">}</span> <span class="token keyword">public</span> <span class="token class-name">JSONObject</span> <span class="token function">makeResultJSONObject</span><span class="token punctuation">(</span><span class="token class-name">String</span> code<span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token class-name">JSONObject</span> sucJSON <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">JSONObject</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token keyword">try</span> <span class="token punctuation">{</span> <span class="token class-name">String</span> state <span class="token operator">=</span> <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">getValue</span><span class="token punctuation">(</span><span class="token string">"state"</span><span class="token punctuation">)</span><span class="token punctuation">;</span> sucJSON<span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span><span class="token string">"state"</span><span class="token punctuation">,</span> state<span class="token punctuation">)</span><span class="token punctuation">;</span> sucJSON<span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span><span class="token string">"authResult"</span><span class="token punctuation">,</span> code<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token punctuation">}</span> <span class="token keyword">catch</span> <span class="token punctuation">(</span><span class="token class-name">JSONException</span> var3<span class="token punctuation">)</span> <span class="token punctuation">{</span> var3<span class="token punctuation">.</span><span class="token function">printStackTrace</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token punctuation">}</span> <span class="token keyword">return</span> sucJSON<span class="token punctuation">;</span> <span class="token punctuation">}</span><span class="token punctuation">}</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre></li><li><p>在dcloud_properties.xml文件中,搜索OAuth,在name=”OAuth”的<code><feature></code>中添加一行<code><module></code></p><pre class="line-numbers language-xml" data-language="xml"><code class="language-xml"><span class="token tag"><span class="token tag"><span class="token punctuation"><</span>feature</span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>OAuth<span class="token punctuation">"</span></span> <span class="token attr-name">value</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>io.dcloud.feature.oauth.OAuthFeatureImpl<span class="token punctuation">"</span></span><span class="token punctuation">></span></span> <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>module</span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>OAuth-Weixin<span class="token punctuation">"</span></span> <span class="token attr-name">value</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>io.dcloud.feature.oauth.weixin.WeiXinOAuthService<span class="token punctuation">"</span></span><span class="token punctuation">/></span></span> <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>module</span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>OAuth-QQ<span class="token punctuation">"</span></span> <span class="token attr-name">value</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>io.dcloud.feature.oauth.qq.QQOAuthService<span class="token punctuation">"</span></span><span class="token punctuation">/></span></span> <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>module</span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>OAuth-Sina<span class="token punctuation">"</span></span> <span class="token attr-name">value</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>io.dcloud.feature.oauth.sina.SinaOAuthService<span class="token punctuation">"</span></span><span class="token punctuation">/></span></span> <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>module</span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>OAuth-Qihoo<span class="token punctuation">"</span></span> <span class="token attr-name">value</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>io.dcloud.oauth.qihoo.QihooOAuthService<span class="token punctuation">"</span></span><span class="token punctuation">/></span></span> <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>module</span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>OAuth-MiUi<span class="token punctuation">"</span></span> <span class="token attr-name">value</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>io.dcloud.feature.oauth.miui.MiUiOAuthService<span class="token punctuation">"</span></span><span class="token punctuation">/></span></span> <span class="token tag"><span class="token tag"><span class="token punctuation"><</span>module</span> <span class="token attr-name">name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>OAuth-QyWeixin<span class="token punctuation">"</span></span> <span class="token attr-name">value</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>io.dcloud.HelloH5.wxapi.QyWeiXinOAuthService<span class="token punctuation">"</span></span><span class="token punctuation">/></span></span><span class="token tag"><span class="token tag"><span class="token punctuation"></</span>feature</span><span class="token punctuation">></span></span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre></li><li><p>在AndroidManifest.xml文件中,添加企业微信appid和agentid的定义</p><pre class="line-numbers language-xml" data-language="xml"><code class="language-xml"><span class="token tag"><span class="token tag"><span class="token punctuation"><</span>meta-data</span> <span class="token attr-name"><span class="token namespace">android:</span>name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>QYWX_APPID<span class="token punctuation">"</span></span> <span class="token attr-name"><span class="token namespace">android:</span>value</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>ww**********cfae<span class="token punctuation">"</span></span> <span class="token punctuation">/></span></span><span class="token tag"><span class="token tag"><span class="token punctuation"><</span>meta-data</span> <span class="token attr-name"><span class="token namespace">android:</span>name</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>QYWX_AGENTID<span class="token punctuation">"</span></span> <span class="token attr-name"><span class="token namespace">android:</span>value</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>1000006<span class="token punctuation">"</span></span> <span class="token punctuation">/></span></span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre></li></ul></li></ol><h3 id="五、关键!webAPP与Android之间的通信,传递参数"><a href="#五、关键!webAPP与Android之间的通信,传递参数" class="headerlink" title="五、关键!webAPP与Android之间的通信,传递参数"></a>五、<span style="color:red">关键!</span>webAPP与Android之间的通信,传递参数</h3><ol><li><h4 id="webAPP端"><a href="#webAPP端" class="headerlink" title="webAPP端"></a>webAPP端</h4><p>接口说明链接:<a href="http://www.html5plus.org/doc/zh_cn/oauth.html#plus.oauth.getServices">OAuth模块</a></p><p>如果你也是和我一样用Vue开发的APP,可以这样写</p><pre class="line-numbers language-javascript" data-language="javascript"><code class="language-javascript"><span class="token keyword">let</span> instance <span class="token operator">=</span> <span class="token keyword">this</span><span class="token punctuation">;</span><span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token operator">!</span>window<span class="token punctuation">.</span>plus<span class="token punctuation">)</span> <span class="token keyword">return</span><span class="token punctuation">;</span>plus<span class="token punctuation">.</span>oauth<span class="token punctuation">.</span><span class="token function">getServices</span><span class="token punctuation">(</span><span class="token keyword">function</span><span class="token punctuation">(</span><span class="token parameter">services</span><span class="token punctuation">)</span><span class="token punctuation">{</span><span class="token keyword">var</span> qyweixin<span class="token punctuation">;</span> <span class="token keyword">for</span><span class="token punctuation">(</span><span class="token keyword">var</span> i <span class="token keyword">in</span> services<span class="token punctuation">)</span><span class="token punctuation">{</span> <span class="token keyword">var</span> service<span class="token operator">=</span>services<span class="token punctuation">[</span>i<span class="token punctuation">]</span><span class="token punctuation">;</span> console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token constant">JSON</span><span class="token punctuation">.</span><span class="token function">stringify</span><span class="token punctuation">(</span>service<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token keyword">if</span><span class="token punctuation">(</span>service<span class="token punctuation">.</span>id <span class="token operator">==</span> <span class="token string">"qyweixin"</span><span class="token punctuation">)</span><span class="token punctuation">{</span> qyweixin <span class="token operator">=</span> service<span class="token punctuation">;</span> <span class="token keyword">break</span><span class="token punctuation">;</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> <span class="token keyword">if</span><span class="token punctuation">(</span>qyweixin<span class="token punctuation">)</span><span class="token punctuation">{</span> qyweixin<span class="token punctuation">.</span><span class="token function">login</span><span class="token punctuation">(</span><span class="token keyword">function</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span> <span class="token comment">// Toast(JSON.stringify(qyweixin.authResult));</span> instance<span class="token punctuation">.</span><span class="token function">getUserInfo</span><span class="token punctuation">(</span>qyweixin<span class="token punctuation">.</span>authResult<span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token comment">//根据code和access_token获取用户信息</span> <span class="token punctuation">}</span><span class="token punctuation">,</span><span class="token keyword">function</span><span class="token punctuation">(</span><span class="token parameter">e</span><span class="token punctuation">)</span><span class="token punctuation">{</span> plus<span class="token punctuation">.</span>nativeUI<span class="token punctuation">.</span><span class="token function">alert</span><span class="token punctuation">(</span><span class="token string">"详情错误信息请参考授权登录(OAuth)规范文档:http://www.html5plus.org/#specification#/specification/OAuth.html"</span><span class="token punctuation">,</span><span class="token keyword">null</span><span class="token punctuation">,</span><span class="token string">"登录失败["</span><span class="token operator">+</span>e<span class="token punctuation">.</span>code<span class="token operator">+</span><span class="token string">"]:"</span><span class="token operator">+</span>e<span class="token punctuation">.</span>message<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span><span class="token punctuation">,</span><span class="token keyword">function</span><span class="token punctuation">(</span><span class="token parameter">e</span><span class="token punctuation">)</span><span class="token punctuation">{</span> <span class="token function">Toast</span><span class="token punctuation">(</span><span class="token string">'获取登录认证失败:'</span><span class="token operator">+</span>e<span class="token punctuation">.</span>message<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre></li><li><h4 id="Android端"><a href="#Android端" class="headerlink" title="Android端"></a>Android端</h4><p><strong>同步执行方法:</strong>JSUtil.wrapJsVar(“Html5 Plus Plugin Hello1!”,true);</p><blockquote><p><code>String wrapJsVar(String value, boolean isString);</code></p><p>转换JS层的返回值,也用于异步接口中回调函数的参数。</p><p><strong>参数说明:</strong><br><strong>value:</strong> 要返回到JS层的值<br><strong>isString:</strong>返回值类型是否为原始字符串<br><strong>返回方法:</strong><br><strong>boolea类型:</strong> wrapJSVar( “true”, false );<br><strong>Number类型:</strong> wrapJsVar( “99”, false );<br><strong>String类型:</strong> wrapJsVar( “hello”, true );<br><strong>数组类型:</strong> wrapJsVar( “[1,2,3,4,5]”, false );<br><strong>JSON类型:</strong> wrapJsVar( “{‘name’:’value’}”, false );</p></blockquote><p><strong>异步执行方法:</strong>JSUtil.execCallback(pWebview , pCallbackId, msg, JSUtil.ERROR, true, false);</p><blockquote><p><code>String execCallback(IWebview pWebView, String pCallbackId, String pMessage, int pStatus, boolean isJson, boolean pKeepCallback);</code></p><p>触发扩展插件中的回调方法。</p><p><strong>参数说明:</strong><br><strong>pWebView:</strong>扩展插件方法运行的窗口<br><strong>pCallbackId:</strong>回调函数的唯一标识<br><strong>pMessage:</strong>回调函数的参数<br><strong>pStatus:</strong>操作是否成功,成功则使用JSUtil.OK,否则使用错误代码<br><strong>isJson:</strong>回调函数参数是否为JSON数据<br><strong>pKeepCallback:</strong>是否可多次触发回调函数</p></blockquote></li><li><h4 id="后端"><a href="#后端" class="headerlink" title="后端"></a>后端</h4><p>根据得到的code获取企业微信的userInfo,这里用到了<a href="https://gitee.com/binary/weixin-java-tools">WxJava</a>,具体整合方法这里就不再过多的叙述了,具体可以查看文档<a href="https://github.com/Wechat-Group/WxJava/wiki/%E4%BC%81%E4%B8%9A%E5%8F%B7%E5%BC%80%E5%8F%91%E6%96%87%E6%A1%A3">企业号开发文档</a>,java代码如下:</p><pre class="line-numbers language-java" data-language="java"><code class="language-java"><span class="token class-name">String</span> accessToken <span class="token operator">=</span> <span class="token string">""</span><span class="token punctuation">;</span><span class="token class-name">WxCpDefaultConfigImpl</span> config <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">WxCpDefaultConfigImpl</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>config<span class="token punctuation">.</span><span class="token function">setCorpId</span><span class="token punctuation">(</span><span class="token string">"ww*********fae"</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// 设置微信企业号的appid</span>config<span class="token punctuation">.</span><span class="token function">setCorpSecret</span><span class="token punctuation">(</span><span class="token string">"lv**********************fu1S02c0"</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// 设置微信企业号的app corpSecret</span>config<span class="token punctuation">.</span><span class="token function">setAgentId</span><span class="token punctuation">(</span><span class="token number">1000006</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// 设置微信企业号应用ID</span><span class="token class-name">WxCpServiceImpl</span> wxCpService <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">WxCpServiceImpl</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>wxCpService<span class="token punctuation">.</span><span class="token function">setWxCpConfigStorage</span><span class="token punctuation">(</span>config<span class="token punctuation">)</span><span class="token punctuation">;</span>accessToken <span class="token operator">=</span> wxCpService<span class="token punctuation">.</span><span class="token function">getAccessToken</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token class-name">WxCpOauth2UserInfo</span> res <span class="token operator">=</span> wxCpService<span class="token punctuation">.</span><span class="token function">getOauth2Service</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">getUserInfo</span><span class="token punctuation">(</span>code<span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token comment">//根据userId获取详细信息</span><span class="token class-name">WxCpUser</span> weChatUser <span class="token operator">=</span> wxCpService<span class="token punctuation">.</span><span class="token function">getUserService</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">getById</span><span class="token punctuation">(</span>res<span class="token punctuation">.</span><span class="token function">getUserId</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre></li></ol><h3 id="六、在企业微信企业管理后台中进行配置"><a href="#六、在企业微信企业管理后台中进行配置" class="headerlink" title="六、在企业微信企业管理后台中进行配置"></a>六、在企业微信企业管理后台中进行配置</h3><ol><li><p>在自建应用中,启用企业微信授权登录</p><p><img src="https://i.loli.net/2021/01/22/ErJeIFib5ORQa7L.png"> </p></li><li><p>还记得我们在第一步,手机端下载的生成签名的APP吗,这里就需要用到它了,在HBuilder-Hello项目的AndroidManifest.xml文件中可以查看到当前项目的包名</p><pre class="line-numbers language-xml" data-language="xml"><code class="language-xml"><span class="token tag"><span class="token tag"><span class="token punctuation"><</span>manifest</span> <span class="token attr-name"><span class="token namespace">xmlns:</span>android</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>http://schemas.android.com/apk/res/android<span class="token punctuation">"</span></span> <span class="token attr-name"><span class="token namespace">xmlns:</span>tools</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>http://schemas.android.com/tools<span class="token punctuation">"</span></span> <span class="token attr-name">package</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>io.dcloud.HelloH5<span class="token punctuation">"</span></span><span class="token punctuation">></span></span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span></span></code></pre></li><li><p>在APP中输入包名,得到签名回填到企业微信管理后台</p><p><img src="https://i.loli.net/2021/01/22/AC34EVwWPgMl6bp.png"> </p><hr><p>至此,整个过程就完美结束啦~ <span class="github-emoji"><span>💮</span><img src="https://github.githubassets.com/images/icons/emoji/unicode/1f4ae.png?v8" aria-hidden="true" onerror="this.parent.classList.add('github-emoji-fallback')"></span></p></li></ol>]]></content>
<categories>
<category> 技术文档 </category>
</categories>
<tags>
<tag> Android </tag>
<tag> WebApp </tag>
<tag> 企业微信 </tag>
</tags>
</entry>
<entry>
<title>毕业季</title>
<link href="/2020/10/01/bi-ye-ji/"/>
<url>/2020/10/01/bi-ye-ji/</url>
<content type="html"><![CDATA[<h3 id="在广袤的空间和无限的时间中-能与你们共享一颗行星和同一段时光-是我的荣幸"><a href="#在广袤的空间和无限的时间中-能与你们共享一颗行星和同一段时光-是我的荣幸" class="headerlink" title="在广袤的空间和无限的时间中,能与你们共享一颗行星和同一段时光,是我的荣幸"></a><strong><font color="#996699">在广袤的空间和无限的时间中,能与你们共享一颗行星和同一段时光,是我的荣幸</font></strong></h3><hr><p><img src="https://raw.githubusercontent.com/Zoracxz/Random-img/master/house.jpg" alt="love & peace"></p><h2 id="我们想说的话"><a href="#我们想说的话" class="headerlink" title="我们想说的话"></a>我们想说的话</h2><p>黄 🐕:</p><blockquote><p>我总是说要去娟(我的锤子)家里,去吃她家的鸽子(虽然她不让我吃,但谁又 care 呢)去看她家的梯田,去感受一下在这样一个热情热烈的家庭里有多么的舒心幸福。可是都毕业了我还是没去成。</p></blockquote><hr><blockquote><p>总是答应丽珍(我的犬儿子)要和她去日本,去长白山,去西宁,去遍所有地方玩,要带她来北海吃粉(但是不许她住我家,让她去流浪)带她去涠洲岛玩。可是到最后毕业了,我还是骗了她哈哈哈哈哈哈。</p></blockquote><hr><blockquote><p>总是说要在猪哥(我的 BABA)还在日本读书的时候去日本,和丽珍一起找她玩,住她的宿舍睡她的床占用她的时间陪我们玩(都是丽珍说的,丽珍赖皮天下无敌)。可是到猪哥回长沙了我还是没去成,又让丽珍狗儿子一个人去了哈哈哈哈哈哈哈。</p></blockquote><hr><blockquote><p>遗憾这两天没有回去和她们一起度过最后这些打闹的时间,想到以后不会再听到丽珍独特的大嗓门,姨妈痛时哭天撼地的声音,委屈的说我们不关心她哈哈哈,再不会有人深更半夜掀我床帘了,再也不能跑到丽珍床上揍她了,再也不能深更半夜在亚娟的床底下桌子上用她的电脑写作业,再也不能跟亚娟一起出去逛理工北门了,再也不能调侃亚娟那些哥哥们了,再也不能看到亚娟整天徘徊在我的衣服包包旁边那暗示的眼神,如果能重来一次我一定会告诉你! 休想碰!再也不能让猪哥介绍日本小哥哥给我(其实是亚娟)认识了,再也不能让猪哥给我考试前临时抱佛脚了,再也不能吃到猪哥从家里带来的辣条和酱板鸭了,再也不能吃到猪哥做的辣椒炒肉(我的最爱)了!!!!<br> 离开了她们我真的好伤心,以后路上再也没有人给我搭肩膀了(虽然我都开小电驴),我再也不能在宿舍一挑二把猪和狗干趴下了哈哈哈哈哈哈(小意思小意思,不用夸我),再也不能在床上使唤她们帮我拿东西了(床上生根了没办法),再也不能在亚娟电脑上我的专属文件夹里增加属于我的东西了(在亚娟的电脑里我的专属文件夹大概也就占一半内存吧哈哈哈哈哈),再也不能挤在同一个地方看剧(明明自己的手机也能看),再也不能一个宿舍下飞行棋,让我成为最后的王者(她们都不如我,玩的真没意思),再也不能和她们一起出去吃饭了(真的只是吃饭,我们宿舍的活动你们不懂),最重要的是,再也不能在同一片天空下住在同一个宿舍呼吸着同一处空气做着属于我们的美梦了,即使听着丽珍的呼噜声也是美的(或许吧),将来的我们会是什么样子的,我想象不出来,我们都是有无限可能的,是最美好的自己,是彼此道路上冉冉升起的新星,是一段不可磨灭的独一无二的美好的记忆。<br>我们,就是我们,是我最爱的我们!<br>我想不到花里胡哨的祝福,只希望我们都<strong>万事顺遂,毫无蹉跎。</strong><br>我的狗儿子们你们要加油!要悄悄的拔尖懂吗!<br><br><br><br><img src="https://github.com/Zoracxz/Random-img/raw/master/line.png" alt="我是分割线"></p></blockquote><p>娟:</p><blockquote><p><strong><font color="#FF9966">在夏天遇见的就在夏天告别吧</font></strong></p><blockquote><p><a href="https://mp.weixin.qq.com/s/kkCKPbjUSPDm0gHAGDeJGQ"><font color="#99CC99">この夏</font></a></p></blockquote></blockquote><p><img src="https://github.com/Zoracxz/Random-img/raw/master/start.jpg" alt="银河"><br>我很庆幸在最美好的时间里遇到你们,希望我们未来都越来越好。</p>]]></content>
<tags>
<tag> 生活 </tag>
</tags>
</entry>
</search>