<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>未分类 &#8211; 「马马虎虎」</title>
	<atom:link href="https://www.gek6.cn/category/uncategorized/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.gek6.cn</link>
	<description>极客蜗牛-开发效率很慢的...</description>
	<lastBuildDate>Wed, 22 May 2024 08:06:56 +0000</lastBuildDate>
	<language>zh-Hans</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.6.2</generator>

<image>
	<url>https://www.gek6.cn/wp-content/uploads/2021/12/20211205200322145-32x32.png</url>
	<title>未分类 &#8211; 「马马虎虎」</title>
	<link>https://www.gek6.cn</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>微信图床之浏览器直传</title>
		<link>https://www.gek6.cn/%e5%be%ae%e4%bf%a1%e5%9b%be%e5%ba%8a%e4%b9%8b%e6%b5%8f%e8%a7%88%e5%99%a8%e7%9b%b4%e4%bc%a0/</link>
					<comments>https://www.gek6.cn/%e5%be%ae%e4%bf%a1%e5%9b%be%e5%ba%8a%e4%b9%8b%e6%b5%8f%e8%a7%88%e5%99%a8%e7%9b%b4%e4%bc%a0/#respond</comments>
		
		<dc:creator><![CDATA[lane]]></dc:creator>
		<pubDate>Wed, 22 May 2024 07:40:07 +0000</pubDate>
				<category><![CDATA[未分类]]></category>
		<guid isPermaLink="false">https://www.gek6.cn/?p=219</guid>

					<description><![CDATA[将微信公众号素材库当作图床使用 &#46;&#46;&#46;]]></description>
										<content:encoded><![CDATA[<blockquote>
<p>将微信公众号素材库当作图床使用</p>
</blockquote>
<h3>第一步服务端获取公众号的access_token</h3>
<pre><code class="language-typescript">async getWechatServiceAccountAccessToken(appid: string, appsecret: string) {
  let accessToken = await this.cacheManager.get(`${appid}_access_token`);
  if (accessToken) {
    return accessToken;
  }
  let res = await axios.get(
    `https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&amp;appid=${appid}&amp;secret=${appsecret}`
  );
  console.log(res.data);
  // noinspection SpellCheckingInspection
  if (res.data[&#039;errcode&#039;]) {
    // noinspection SpellCheckingInspection
    throw new Error(res.data[&#039;errmsg&#039;]);
  } else {
    await this.cacheManager.set(
      `${appid}_access_token`,
      res.data[&#039;access_token&#039;],
      {
        ttl: 7000,
      }
    );
    return res.data[&#039;access_token&#039;];
  }
}</code></pre>
<h3>第二部 浏览器端直接传</h3>
<h4>HTML</h4>
<pre><code class="language-html">&lt;el-upload
  action=&quot;#&quot;
  :http-request=&quot;uploadHandler&quot;
  :drag=&quot;true&quot;
  :name=&quot;&#039;media&#039;&quot;
  :show-file-list=&quot;false&quot;
>
  &lt;el-icon&gt;&lt;plus /&gt;&lt;/el-icon&gt;
  &lt;template #tip&gt;
   &lt;div class=&quot;el-upload__tip&quot;&gt;只能上传jpg/png文件，且不超过10MB&lt;/div&gt;
  &lt;/template&gt;
&lt;/el-upload&gt;</code></pre>
<h4>JS</h4>
<pre><code class="language-ts">const uploadActionUrl = computed(() =&gt; {
  return `/wechat-api/cgi-bin/material/add_material?access_token=${wechatAccessToken.value}&amp;type=image`;
});
let wechatAccessToken = ref(&quot;&quot;);
async function uploadHandler({ file }: UploadRequestOptions) {
  console.log(file);
  const formData = new FormData();
  formData.append(&quot;media&quot;, file, file.name);
  let res = await axios.post(uploadActionUrl.value, formData, {});
  console.log(res);
}</code></pre>
<h4>上传截图</h4>
<p><img decoding="async" src="https://p6-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/cc724ec3f1644db9ab9168019e3947a5~tplv-k3u1fbpfcp-jj-mark:0:0:0:0:q75.image#?w=959\&amp;h=391\&amp;s=29432\&amp;e=png\&amp;b=fbfbfb" alt="image.png" /></p>
<p><img decoding="async" src="https://p1-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/f37cc9a3d05048039bc16ee5725cbfc4~tplv-k3u1fbpfcp-jj-mark:0:0:0:0:q75.image#?w=770\&amp;h=180\&amp;s=18008\&amp;e=png\&amp;b=fdfdfd" alt="image.png" /></p>
<h4>下面这个就是微信素材库的图</h4>
<p><img decoding="async" src="http://mmbiz.qpic.cn/mmbiz_jpg/HEkzn2aI6dBJ3LoqcjDlKynsx7BHMOIN4XR2f0pw07xrlKsaZHDaCQqM5o9nhypGvzWyeIBo0v0MSQVPOgbCTA/0?wx_fmt=jpeg" alt="这个就是微信素材库的图" /></p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.gek6.cn/%e5%be%ae%e4%bf%a1%e5%9b%be%e5%ba%8a%e4%b9%8b%e6%b5%8f%e8%a7%88%e5%99%a8%e7%9b%b4%e4%bc%a0/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
