<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>笔记 on 阿珏酱のBlog</title>
    <link>https://zh.moejue.cn/tags/%E7%AC%94%E8%AE%B0/</link>
    <description>Recent content from 阿珏酱のBlog</description>
    <generator>Hugo</generator>
    <language>zh-cn</language>
    
    <managingEditor>xxx@example.com (MoeJue)</managingEditor>
    <webMaster>xxx@example.com (MoeJue)</webMaster>
    
    <copyright>本博客所有文章除特别声明外，均采用 BY-NC-SA 许可协议。转载请注明出处！</copyright>
    
    <lastBuildDate>Sun, 06 Jul 2025 14:25:00 +0000</lastBuildDate>
    
    
    <atom:link href="https://zh.moejue.cn/tags/%E7%AC%94%E8%AE%B0/index.xml" rel="self" type="application/rss&#43;xml" />
    

    
    

    <item>
      <title>什么是Web3.0，和区块链又有什么关系？</title>
      <link>https://zh.moejue.cn/posts/202/</link>
      <pubDate>Mon, 17 Jun 2024 12:59:22 &#43;0000</pubDate>
      <author>xxx@example.com (MoeJue)</author>
      <guid>https://zh.moejue.cn/posts/202/</guid>
      <description>
        <![CDATA[<h1>什么是Web3.0，和区块链又有什么关系？</h1><p>作者：MoeJue（xxx@example.com）</p>
        
          <p>又是一个莫名其妙的词语的新起-。- 我大致归纳为以下几个点</p>
<h2 id="什么是web30">
<a class="header-anchor" href="#%e4%bb%80%e4%b9%88%e6%98%afweb30"></a>
什么是web3.0
</h2><p>Web 3.0（Web3）是下一代互联网的发展方向，旨在创建一个更加去中心化、用户控制和数据保护的网络环境。与之前的Web 1.0（静态网页）和Web 2.0（动态、交互式网页和社交媒体）不同，Web 3.0的核心理念和技术包括以下几个方面：</p>
<h3 id="去中心化">
<a class="header-anchor" href="#%e5%8e%bb%e4%b8%ad%e5%bf%83%e5%8c%96"></a>
去中心化：
</h3><ul>
<li>区块链技术：Web 3.0的核心是区块链技术，它提供了一个去中心化的账本，记录所有的交易和数据变化。这意味着数据不再由单一的中央服务器控制，而是分布在多个节点上。</li>
<li>分布式应用（DApps）：这些应用程序运行在区块链网络上，没有中心化的控制者。DApps的用户可以直接进行交易和互动，而无需通过中介机构。</li>
</ul>
<h3 id="用户控制和数据保护">
<a class="header-anchor" href="#%e7%94%a8%e6%88%b7%e6%8e%a7%e5%88%b6%e5%92%8c%e6%95%b0%e6%8d%ae%e4%bf%9d%e6%8a%a4"></a>
用户控制和数据保护：
</h3><ul>
<li>用户主权身份：在Web 3.0中，用户可以完全控制自己的数字身份和数据。通过加密技术，用户可以决定谁可以访问他们的数据以及如何使用这些数据。</li>
<li>数据所有权：用户的数据存储在去中心化的网络上，用户拥有数据的所有权，而不是由大公司集中管理和控制。</li>
</ul>
<h3 id="智能合约">
<a class="header-anchor" href="#%e6%99%ba%e8%83%bd%e5%90%88%e7%ba%a6"></a>
智能合约：
</h3><ul>
<li>
<p>自动执行协议：智能合约是在区块链上运行的自动化协议，当满足特定条件时自动执行。这种技术可以用于各种场景，如金融交易、供应链管理和法律合同。 互操作性：</p>
</li>
<li>
<p>跨平台和跨链技术：Web 3.0致力于实现不同区块链和分布式网络之间的互操作性，使得数据和资产可以在不同平台之间无缝转移。</p>
</li>
</ul>
<h3 id="去信任化和透明度">
<a class="header-anchor" href="#%e5%8e%bb%e4%bf%a1%e4%bb%bb%e5%8c%96%e5%92%8c%e9%80%8f%e6%98%8e%e5%ba%a6"></a>
去信任化和透明度：
</h3><ul>
<li>无信任机制：Web 3.0通过区块链技术实现了无信任机制，即参与者无需互相信任或依赖第三方中介，就能进行安全的交易和互动。</li>
<li>透明性：所有交易和数据变更记录在区块链上，公开透明且不可篡改，提高了信任度和安全性。</li>
</ul>
<h3 id="web-30的应用场景">
<a class="header-anchor" href="#web-30%e7%9a%84%e5%ba%94%e7%94%a8%e5%9c%ba%e6%99%af"></a>
Web 3.0的应用场景
</h3><ol>
<li>去中心化金融（DeFi）：通过智能合约和区块链技术，提供无需中介的金融服务，如借贷、交易和投资。</li>
<li>数字身份：用户可以创建和管理自己的数字身份，控制个人数据的访问和使用。</li>
<li>供应链管理：通过区块链技术，实现供应链的透明和可追溯性，防止伪造和欺诈。</li>
<li>内容创作和分发：艺术家、音乐家和作家可以直接与观众互动和交易，获得更公平的收益分配。</li>
</ol>
<h2 id="那什么又是区块链呢">
<a class="header-anchor" href="#%e9%82%a3%e4%bb%80%e4%b9%88%e5%8f%88%e6%98%af%e5%8c%ba%e5%9d%97%e9%93%be%e5%91%a2"></a>
那什么又是区块链呢？
</h2><p>区块链技术是一种分布式账本技术（Distributed Ledger Technology, DLT），用于记录交易和信息的不可篡改、去中心化的数据库。区块链技术的核心思想是通过去中心化的方式实现数据的安全、透明和可信。</p>
<h3 id="区块链的基本原理">
<a class="header-anchor" href="#%e5%8c%ba%e5%9d%97%e9%93%be%e7%9a%84%e5%9f%ba%e6%9c%ac%e5%8e%9f%e7%90%86"></a>
区块链的基本原理
</h3><ol>
<li>
<p>区块（Block）：</p>
<ul>
<li>区块是包含交易记录的数据包。每个区块包含多个交易和一个哈希值（用于唯一标识该区块）。</li>
<li>区块还包含上一个区块的哈希值，从而将所有区块连接成链，形成区块链。</li>
</ul>
</li>
<li>
<p>链（Chain）：</p>
<ul>
<li>区块通过哈希值相互连接，形成一个链式结构。每个区块包含前一个区块的哈希值，这使得区块链中的数据难以篡改。</li>
<li>如果试图更改一个区块中的数据，将导致该区块及其后续所有区块的哈希值发生变化，需要重新计算所有这些区块的哈希值，这几乎是不可能的。</li>
</ul>
</li>
<li>
<p>去中心化（Decentralization）：</p>
<ul>
<li>区块链网络中的所有节点（计算机）都保存一个完整的区块链副本，这些副本通过共识机制保持一致。</li>
<li>没有中央机构控制或管理区块链，数据由所有节点共同维护。</li>
</ul>
</li>
<li>
<p>共识机制（Consensus Mechanism）：</p>
<ul>
<li>区块链网络使用共识机制来确保所有节点对区块链的状态达成一致。常见的共识机制包括工作量证明（Proof of Work, PoW）和权益证明（Proof of Stake, PoS）。</li>
<li>工作量证明（PoW）：矿工通过解决复杂的数学问题来验证交易，并将其添加到区块链中。解决问题需要大量计算能力，确保了区块链的安全性。 权益证明（PoS）：验证者根据其持有的加密货币数量和其他因素来验证交易，并获得相应的奖励。</li>
</ul>
</li>
<li>
<p>加密技术（Cryptography）： -区块链使用加密技术确保数据的安全性和隐私性。每个交易都使用公钥和私钥进行签名和验证，确保只有合法的所有者才能发起交易。</p>
        
        <hr><p>本文2024-06-17首发于<a href='https://zh.moejue.cn/'>阿珏酱のBlog</a>，最后修改于2025-07-06</p>]]>
      </description>
      
        <category>教程</category>
      
    </item>
    
    

    <item>
      <title>多链支持，真没你想的那么简单</title>
      <link>https://zh.moejue.cn/posts/269/</link>
      <pubDate>Sat, 05 Jul 2025 08:20:55 &#43;0000</pubDate>
      <author>xxx@example.com (MoeJue)</author>
      <guid>https://zh.moejue.cn/posts/269/</guid>
      <description>
        <![CDATA[<h1>多链支持，真没你想的那么简单</h1><p>作者：MoeJue（xxx@example.com）</p>
        
          <h4 id="一次多链钱包集成的实践反思">
<a class="header-anchor" href="#%e4%b8%80%e6%ac%a1%e5%a4%9a%e9%93%be%e9%92%b1%e5%8c%85%e9%9b%86%e6%88%90%e7%9a%84%e5%ae%9e%e8%b7%b5%e5%8f%8d%e6%80%9d"></a>
一次多链钱包集成的实践反思
</h4><p>总算是空闲下来可以整理一下代码了，Web3项目接入多链钱包连接功能，主要涉及 Ethereum、Polygon、BSC 和 Solana。乍一听好像只是“多做几套兼容逻辑”的事，但真正落地后才发现，很多东西其实没想得那么简单。</p>
<pre tabindex="0"><code>this.networkConfigs = {
    ethereum: {
        chainId: &#39;0x1&#39;, // 1
        chainName: &#39;Ethereum Mainnet&#39;,
        nativeCurrency: {
            name: &#39;Ethereum&#39;,
            symbol: &#39;ETH&#39;,
            decimals: 18
        },
        rpcUrls: [&#39;https://eth-mainnet.public.blastapi.io&#39;],
        blockExplorerUrls: [&#39;https://etherscan.io&#39;]
    },
    polygon: {
        chainId: &#39;0x89&#39;, // 137
        chainName: &#39;Polygon Mainnet&#39;,
        nativeCurrency: {
            name: &#39;MATIC&#39;,
            symbol: &#39;MATIC&#39;,
            decimals: 18
        },
        rpcUrls: [&#39;https://polygon-rpc.com&#39;],
        blockExplorerUrls: [&#39;https://polygonscan.com&#39;]
    },
    bsc: {
        chainId: &#39;0x38&#39;, // 56
        chainName: &#39;BNB Smart Chain&#39;,
        nativeCurrency: {
            name: &#39;BNB&#39;,
            symbol: &#39;BNB&#39;,
            decimals: 18
        },
        rpcUrls: [&#39;https://bsc-dataseed.binance.org&#39;],
        blockExplorerUrls: [&#39;https://bscscan.com&#39;]
    }
}
</code></pre><h4 id="多链并不是简单的支持多个钱包">
<a class="header-anchor" href="#%e5%a4%9a%e9%93%be%e5%b9%b6%e4%b8%8d%e6%98%af%e7%ae%80%e5%8d%95%e7%9a%84%e6%94%af%e6%8c%81%e5%a4%9a%e4%b8%aa%e9%92%b1%e5%8c%85"></a>
多链并不是简单的「支持多个钱包」
</h4><p>最大的感受是：链不一样，钱包交互方式也不一样，连 SDK 的思维方式都不一样。以太坊生态可以用统一的 Web3.js 处理很多逻辑，而到了 Solana，你会发现它完全是另一套系统：Provider 接入、连接流程、PublicKey 构建方式都不太一样，甚至连网络延迟和稳定性都影响体验。</p>
        
        <hr><p>本文2025-07-05首发于<a href='https://zh.moejue.cn/'>阿珏酱のBlog</a>，最后修改于2025-07-05</p>]]>
      </description>
      
        <category>折腾代码</category>
      
    </item>
    
    

    <item>
      <title>Git简单的使用步骤</title>
      <link>https://zh.moejue.cn/posts/64/</link>
      <pubDate>Tue, 03 Apr 2018 12:04:32 &#43;0000</pubDate>
      <author>xxx@example.com (MoeJue)</author>
      <guid>https://zh.moejue.cn/posts/64/</guid>
      <description>
        <![CDATA[<h1>Git简单的使用步骤</h1><p>作者：MoeJue（xxx@example.com）</p>
        
          <p>本文并不阐述任何概念性知识，仅仅只是做一个笔记，简单是使用步骤，如遇障碍，请Google一下</p>
<ul>
<li>使用SSH 完成 Git 与 GitHub 的绑定</li>
</ul>
<p>1. 生成 <code>SSH key</code></p>
<p>ssh-keygen -t rsa</p>
<p>指定 RSA 算法生成密钥，之后就就会生成两个文件，分别为id_rsa和id_rsa.pub，即密钥id_rsa和公钥id_rsa.pub. 对于这两个文件</p>
<p>2. 添加 SSH key<br>
github.com -&gt; Settings -&gt; SSH and GPG -&gt; New SSH key<br>
将公钥id_rsa.pub的内容粘贴到Key处的位置（Titles的内容不填写也没事），然后点击Add SSH key 即可。</p>
<p>3. 验证绑定是否成功</p>
<p>ssh -T <a href="mailto:git@github.com">git@github.com</a></p>
<ul>
<li>把本地项目推送到github的命令</li>
</ul>
<p>(1) 打开你的目录</p>
<p>cd demo</p>
<p>(2) 初始化版本库，用于生成git文件</p>
<p>git init</p>
<p>(3) 将所有文件添加到缓存区</p>
<p>git add *</p>
<p>(4) 提交当前工作空间的修改内容</p>
<p>git commit -m &ldquo;first commit&rdquo;</p>
<p>(5) 将仓库连接到远程服务器</p>
<p>git remote add origin <server>(就是上面你仓库的地址)</p>
<p>(6) 将改动推送到所添加的服务器上</p>
        
        <hr><p>本文2018-04-03首发于<a href='https://zh.moejue.cn/'>阿珏酱のBlog</a>，最后修改于2025-06-02</p>]]>
      </description>
      
        <category>教程</category>
      
    </item>
    
    

    <item>
      <title>[笔记]Git常用命令大全</title>
      <link>https://zh.moejue.cn/posts/57/</link>
      <pubDate>Sat, 16 Jun 2018 08:56:21 &#43;0000</pubDate>
      <author>xxx@example.com (MoeJue)</author>
      <guid>https://zh.moejue.cn/posts/57/</guid>
      <description>
        <![CDATA[<h1>[笔记]Git常用命令大全</h1><p>作者：MoeJue（xxx@example.com）</p>
        
          <p>继上一次后，抽空整理了个比较全的Git常用命令，找到了一张非常棒的导图，非常高清的（1759*3162）。</p>
<p>查看、添加、提交、删除、找回，重置修改文件</p>
<p>git help <command> # 显示command的help</p>
<p>git show # 显示某次提交的内容 git show $id</p>
<p>git co &ndash; <file> # 抛弃工作区修改</p>
<p>git co . # 抛弃工作区修改</p>
<p>git add <file> # 将工作文件修改提交到本地暂存区</p>
<p>git add . # 将所有修改过的工作文件提交暂存区</p>
<p>git rm <file> # 从版本库中删除文件</p>
<p>git rm <file> &ndash;cached # 从版本库中删除文件，但不删除文件</p>
<p>git reset <file> # 从暂存区恢复到工作文件</p>
<p>git reset &ndash; . # 从暂存区恢复到工作文件</p>
<p>git reset &ndash;hard # 恢复最近一次提交过的状态，即放弃上次提交后的所有本次修改</p>
<p>git ci <file> git ci . git ci -a # 将git add, git rm和git ci等操作都合并在一起做　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　git ci -am &ldquo;some comments&rdquo;</p>
        
        <hr><p>本文2018-06-16首发于<a href='https://zh.moejue.cn/'>阿珏酱のBlog</a>，最后修改于2025-06-02</p>]]>
      </description>
      
        <category>折腾代码</category>
      
    </item>
    
    

    <item>
      <title>[笔记] Git 常用命令大全（按场景分类）</title>
      <link>https://zh.moejue.cn/posts/264/</link>
      <pubDate>Mon, 02 Jun 2025 06:58:42 &#43;0000</pubDate>
      <author>xxx@example.com (MoeJue)</author>
      <guid>https://zh.moejue.cn/posts/264/</guid>
      <description>
        <![CDATA[<h1>[笔记] Git 常用命令大全（按场景分类）</h1><p>作者：MoeJue（xxx@example.com）</p>
        
          <blockquote>
<p>适用于日常开发中对 Git 的常见操作。通过分类整理，帮助你快速上手或查阅。</p>
</blockquote>
<hr>
<h2 id="-基础命令">
<a class="header-anchor" href="#-%e5%9f%ba%e7%a1%80%e5%91%bd%e4%bb%a4"></a>
📦 基础命令
</h2><p>命令</p>
<p>作用</p>
<p><code>git init</code></p>
<p>初始化一个 Git 仓库（创建 <code>.git</code> 文件夹）。</p>
<p><code>git clone &lt;url&gt;</code></p>
<p>克隆远程仓库到本地。</p>
<p><code>git status</code></p>
<p>查看当前工作目录状态（文件修改、暂存等）。</p>
<p><code>git add &lt;file&gt;</code></p>
<p>添加文件到暂存区。</p>
<p><code>git commit -m &quot;message&quot;</code></p>
<p>提交暂存区文件到本地仓库，并添加提交信息。</p>
<p><code>git log</code></p>
<p>查看提交历史。</p>
<hr>
<h2 id="-分支管理">
<a class="header-anchor" href="#-%e5%88%86%e6%94%af%e7%ae%a1%e7%90%86"></a>
🌱 分支管理
</h2><p>命令</p>
<p>作用</p>
<p><code>git branch</code></p>
<p>查看本地分支列表。</p>
<p><code>git branch &lt;branch-name&gt;</code></p>
<p>创建一个新分支。</p>
<p><code>git checkout &lt;branch-name&gt;</code></p>
<p>切换到指定分支。</p>
<p><code>git switch &lt;branch-name&gt;</code></p>
<p>切换到指定分支（推荐使用的新命令）。</p>
<p><code>git merge &lt;branch-name&gt;</code></p>
<p>合并指定分支到当前分支。</p>
<p><code>git branch -d &lt;branch-name&gt;</code></p>
<p>删除已合并的分支。</p>
<p><code>git branch -D &lt;branch-name&gt;</code></p>
<p>强制删除分支。</p>
<hr>
<h2 id="-远程仓库操作">
<a class="header-anchor" href="#-%e8%bf%9c%e7%a8%8b%e4%bb%93%e5%ba%93%e6%93%8d%e4%bd%9c"></a>
🌍 远程仓库操作
</h2><p>命令</p>
        
        <hr><p>本文2025-06-02首发于<a href='https://zh.moejue.cn/'>阿珏酱のBlog</a>，最后修改于2025-06-02</p>]]>
      </description>
      
        <category>教程</category>
      
    </item>
    
    

    <item>
      <title>热敏蓝牙打印机开发</title>
      <link>https://zh.moejue.cn/posts/100/</link>
      <pubDate>Tue, 05 Nov 2019 14:49:50 &#43;0000</pubDate>
      <author>xxx@example.com (MoeJue)</author>
      <guid>https://zh.moejue.cn/posts/100/</guid>
      <description>
        <![CDATA[<h1>热敏蓝牙打印机开发</h1><p>作者：MoeJue（xxx@example.com）</p>
        
          <p>最近在做小票打印这块，项目需求是IOS和安卓两种都要实现，开始做的时候也是一脸懵，然后网上找了不少资料，踩了一堆坑，看了好多文章，结果还好成了<br>
蓝牙打印机一般分为两种打印模式，票据打印、标签打印</p>
<p>公司买的渣渣打印机连开发文档都没有，害我走了不少坑，让我开发买的时候也不咨询咨询我<br>
目前微信小程序连接蓝牙打印机 wx.createBLEConnection 测试在IOS设备上没有问题，在部分安卓手机上会出现异常（表现为，连接是会弹出系统配对框，不管点取消还是输入配对码后点确定，都会立马断开连接。如果不输入也不取消则会在30秒以内自动断开蓝牙打印机）</p>
<p>现在采用的方式是各给安卓和IOS写一套蓝牙打印的命令<br>
<strong>IOS</strong></p>
<p>// ====================蓝牙操作==================  //初始化蓝牙模块
openBluetoothAdapter() {</p>
<pre><code>if (app.sysinfo.provider == 1) {
    // 开启蓝牙
    app.onBluetooth()
    setTimeout(() =&gt; {
        this.android\_search()
    }, 2000)
    return false;
}


this.closeBluetoothAdapter()
uni.openBluetoothAdapter({
    success: (res) =&gt; {
        console.log(&quot;初始化蓝牙模块: &quot; + JSON.stringify(res));
        this.startBluetoothDevicesDiscovery()
    },
    fail: (res) =&gt; {
        if (res.errCode === 10001) {
            uni.onBluetoothAdapterStateChange((res) =&gt; {
                console.log('监听蓝牙适配器状态变化事件', res)
                if (res.available == false) {
                    app.global\_printing = {}
                    this.connected = false
                    this.chs = \[\]
                    this.canWrite = false
                }
                if (res.available) {
                    this.startBluetoothDevicesDiscovery()
                }
            })
        }
        if (res.errCode) {
            app.alert('初始化蓝牙失败，错误码：' + res.errCode)
            return false;
        }
        app.alert(res.errMsg)
    }
})
</code></pre>
<p>},</p>
        
        <hr><p>本文2019-11-05首发于<a href='https://zh.moejue.cn/'>阿珏酱のBlog</a>，最后修改于2019-11-05</p>]]>
      </description>
      
        <category>折腾代码</category>
      
    </item>
    
    

    <item>
      <title>微信授权登录</title>
      <link>https://zh.moejue.cn/posts/88/</link>
      <pubDate>Fri, 05 Apr 2019 09:29:45 &#43;0000</pubDate>
      <author>xxx@example.com (MoeJue)</author>
      <guid>https://zh.moejue.cn/posts/88/</guid>
      <description>
        <![CDATA[<h1>微信授权登录</h1><p>作者：MoeJue（xxx@example.com）</p>
        
          <p><img src="https://res.wx.qq.com/mpres/htmledition/weui-desktopSkin/svg/buildless/bg_logo_primary4247a9.svg" alt=""> 文档：<a href="https://mp.weixin.qq.com/wiki?t=resource/res_main&amp;id=mp1421135319">https://mp.weixin.qq.com/wiki?t=resource/res_main&amp;id=mp1421135319</a></p>
<p>微信的授权登录和QQ、新浪等平台的授权登录都大同小异，均采用OauthOAuth2.0鉴权方式。<br>
微信授权分为两种：</p>
<ol>
<li>静默授权</li>
<li>弹窗授权，需要用户手动同意</li>
</ol>
<p>两种scope的区别说明</p>
<ol>
<li>以snsapi_base为scope发起的网页授权，是用来获取进入页面的用户的openid的，并且是静默授权并自动跳转到回调页的。用户感知的就是直接进入了回调页（往往是业务页面）</li>
<li>以snsapi_userinfo为scope发起的网页授权，是用来获取用户的基本信息的。但这种授权需要用户手动同意，并且由于用户同意过，所以无须关注，就可在授权后获取该用户的基本信息。</li>
</ol>
<p>用户管理类接口中的“获取用户基本信息接口”，是在用户和公众号产生消息交互或关注后事件推送后，才能根据用户OpenID来获取用户基本信息。这个接口，包括其他微信接口，都是需要该用户（即openid）关注了公众号后，才能调用成功的。</p>
<p>具体而言，网页授权流程分为四步：</p>
<ol>
<li>引导用户进入授权页面同意授权，获取code</li>
<li>通过code换取网页授权access_token（与基础支持中的access_token不同）</li>
<li>如果需要，开发者可以刷新网页授权access_token，避免过期</li>
<li>通过网页授权access_token和openid获取用户基本信息（支持UnionID机制）</li>
</ol>
<p>以下是封装的微信操作类，需要用到两个数据表，用于保存access_token、ticket，由于他们具有一定有效期，且每天请求数有上限，所以开发者需自行保存</p>
<?php
/\*\*
\*   微信操作表
\*   wxtoken 表结构
\*   id
\*   access\_token
\*   addtime
\*   wxticket 表结构
\*   id
\*   ticket
\*   addtime
\*/
class WX {
	private $appid;
	private $appserect;
	private $curl;
	private $msg;
	protected $errs = array(
		'-1' => '系统繁忙，此时请开发者稍候再试',
		'0' => '请求成功',
		'40001' => 'AppSecret错误或者AppSecret不属于这个公众号，请开发者确认AppSecret的正确性',
		'40002' => '请确保grant\_type字段值为client\_credential',
		'40164' => '调用接口的IP地址不在白名单中，请在接口IP白名单中进行设置。',
	);
	function \_\_construct($appid, $appserect) {
		$this->appid = $appid;
		$this->appserect = $appserect;
		$this->curl = new Curl();
	}
	/\*
	微信网页授权登录  需要在公众号设置 - 功能设置 - 网页授权域名
	第一步：用户同意授权，获取code
	scope : snsapi\_base 只能获取openid 直接跳转
	snsapi\_userinfo
	\*/
	public function getCode($redirect\_uri, $scope = 'snsapi\_userinfo',$state = '1') {
		$url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid={$this->appid}&redirect\_uri={$redirect\_uri}&response\_type=code&scope={$scope}&state={$state}#wechat\_redirect";
		header("Location:{$url}");
		exit;
	}
	/\*
	第二步：通过code换取网页授权access\_token
	\*/
	public function getAccessTokenByCode($code) {
		$url = "https://api.weixin.qq.com/sns/oauth2/access\_token?appid={$this->appid}&secret={$this->appserect}&code={$code}&grant\_type=authorization\_code";
		// exit($url);
		// $curl = new Curl();
		$result = $this->curl->doGet($url);
		if (!$result) {
			// $this->curl->getError()
			$this->msg = "获取token失败";
			return false;
		}
		$result = json\_decode($result, true);
		if ($result\['errcode'\]) {
			$this->msg = $result\['errmsg'\];
			return false;
		}
		return $result;
	}
	// 第三步：刷新access\_token（如果需要） 通过code 获取openid $type 0静默授权 1弹窗授权
	public function getUserInfo($code, $type = 0, $lang = 'zh\_CN ') {
		$result = $this->getAccessTokenByCode($code);
			if (!$result) {
			return false;
		}
		$member = C::t(PT\_USER)->getByOpenid($result\['openid'\]);
	if ($member) {
		return $member;
	} else {
		if ($type) {
			$url = "https://api.weixin.qq.com/sns/userinfo?access\_token={$result\['access\_token'\]}&openid={$result\['openid'\]}&lang={$lang}";
			// $return = $this->curl->doGet($url);
			// 这接口有病 强制显示文件头
			$return = file\_get\_contents($url);
			if (!$return) {
				$this->msg = '获取用户信息失败';
				return false;
			}
			$return = json\_decode($return, true);
			if (!$return) {
				$this->msg = '获取用户信息返回失败';
				return false;
			}
			// file\_put\_contents('ccc.txt',print\_r($return,true),FILE\_APPEND);
			$data = array(
				'openid' => $return\['openid'\],
				'name' => $return\['nickname'\],
				'sex' => $return\['sex'\],
				'province' => $return\['province'\],
				'city' => $return\['city'\],
				'country' => $return\['country'\],
				'img' => $return\['headimgurl'\],
				'bindtel' => 0,
			);
		} else {
			$data = array(
				'openid' => $result\['openid'\],
				'username' => "微信用户\_" . random(6,1)
			);
		}
		$name = rand(100000, 1000000000);
		$e = $name . "@qq.com";
		$password = $e;
		$id = UserAddEdit(0, $data\['username'\], $password, $e,10,0,"", $msg);
		if ($id <= 0) {
			$this->msg = $msg;
			return false;
		}
		C::t(PT\_USER)->update($data, $id);
		$member = C::t(PT\_USER)->get($id);
		return $member;
		}
	}
	/\*
	公众号 安全中心 设置IP白名单
	公众号的全局唯一接口调用凭据，公众号调用各接口时都需使用access\_token。开发者需要进行妥善保存。access\_token的存储至少要保留512个字符空间。access\_token的有效期目前为2个小时，需定时刷新，重复获取将导致上次获取的access\_token失效。
	\*/
	public function getAccessToken($type) {
		$addtime = TIMESTAMP - 7200;
		$url = "https://api.weixin.qq.com/cgi-bin/token?grant\_type=client\_credential&appid={$this->appid}&secret={$this->appserect}";
		$row = C::t(PT\_WXTOKEN)->getNew($addtime, $type);
		if ($row) {
			return $row\['access\_token'\];
		} else {
			$result = $this->curl->doGet($url);
			if (!$result) {
				$this->msg = "无法获取令牌内容";
				return false;
			}
			$result = json\_decode($result, true);
			if (!$result) {
				$this->msg = "解析令牌内容失败";
				return false;
			}
			if ($result\['access\_token'\]) {
				C::t(PT\_WXTOKEN)->addToken($result\['access\_token'\], $type);
				return $result\['access\_token'\];
			} else {
				$this->msg = "获取令牌失败";
				return false;
			}
		}
	}
	// 获取js票据  需要在公众号设置 - 功能设置 - JS接口安全域名设置
	public function getJsTicket() {
		$addtime = TIMESTAMP - 7200;
		$row = C::t(PT\_WXTICKET)->getNew($addtime);
		if ($row) {
			return $row\['ticket'\];
		} else {
			$token = $this->getAccessToken();
			if (!$token) {
				return false;
			}
			$url = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?access\_token={$token}&type=jsapi";
			$result = $this->curl->doGet($url);
			if (!$result) {
				$this->msg = "无法获取js票据";
				return false;
			}
			$result = json\_decode($result, true);
			if (!$result) {
				$this->msg = "解析js票据内容失败";
				return false;
			}
			if ($result\['ticket'\]) {
				C::t(PT\_WXTICKET)->addTicket($result\['ticket'\]);
				return $result\['ticket'\];
			} else {
				$this->msg = "获取js票据失败";
				return false;
			}
		}
	}
	// js sdk 票据签名 当前网页的URL，不包含#及其后面部分
	public function jsSign($data) {
		// 1.所有待签名参数按照字段名的ASCII 码从小到大排序（字典序）
		ksort($data);
		// 2.URL键值对的格式（即key1=value1&key2=value2…）拼接成字符串string1 采用原始值，不进行URL 转义
		$string1 = $this->ToUrlParams($data);
		// echo "string1:{$string1}<br/>";
		// 3.对string1做sha1加密
		$sign = sha1($string1);
		// echo "signature:{$sign}<br/>";
		return $sign;
	}
	// 获取消息内容
	public function getMsg() {
		return $this->msg;
	}
	/\*\*
	\* 格式化参数格式化成url参数
	\*/
	public function ToUrlParams($data) {
		$buff = "";
		foreach ($data as $k => $v) {
			if ($k != "sign" && $v != "" && !is\_array($v)) {
				$buff .= $k . "=" . $v . "&";
			}
		}
		$buff = trim($buff, "&");
		return $buff;
	}
}
?>
<p>// 微信登录
function wxlogin() {
global $_G,$identifier,$config,$wx;
if (!$_G[&lsquo;uid&rsquo;]) {
if ($_GET[&lsquo;state&rsquo;]) {
//回调
$member = $wx-&gt;getUserInfo($_GET[&lsquo;code&rsquo;]);
if (!$member) {
exit($wx-&gt;getMsg());
}
if (!function_exists(&ldquo;setloginstatus&rdquo;)) {
include_once libfile(&lsquo;function/member&rsquo;);
}
// 设置登录状态$wx
setloginstatus($member, 2592000);
checkfollowfeed();
$_G[&lsquo;uid&rsquo;] = $member[&lsquo;uid&rsquo;];
$_G[&lsquo;member&rsquo;] = $member;
} else {
//请求授权 对参数编码
$redirect = urlencode(getProtocol() . $_SERVER[&lsquo;HTTP_HOST&rsquo;] . $_SERVER[&lsquo;REQUEST_URI&rsquo;]);
$wx-&gt;getCode($redirect, &lsquo;snsapi_base&rsquo;);
}
}
}
function getProtocol() {
return is_HTTPS() ? &lsquo;https://&rsquo; : &lsquo;http://&rsquo;;
}
function is_HTTPS() {  if ($_SERVER[&lsquo;HTTPS&rsquo;] === 1 || $_SERVER[&lsquo;HTTPS&rsquo;] === &lsquo;on&rsquo; || $_SERVER[&lsquo;SERVER_PORT&rsquo;] == 443) {
return true;
}
return false;
}</p>
        
        <hr><p>本文2019-04-05首发于<a href='https://zh.moejue.cn/'>阿珏酱のBlog</a>，最后修改于2019-04-05</p>]]>
      </description>
      
        <category>折腾代码</category>
      
    </item>
    
    

    <item>
      <title>微信JSAPI支付</title>
      <link>https://zh.moejue.cn/posts/89/</link>
      <pubDate>Sat, 30 Mar 2019 09:30:21 &#43;0000</pubDate>
      <author>xxx@example.com (MoeJue)</author>
      <guid>https://zh.moejue.cn/posts/89/</guid>
      <description>
        <![CDATA[<h1>微信JSAPI支付</h1><p>作者：MoeJue（xxx@example.com）</p>
        
          <p><img src="https://gh-proxy.com/github.com/iAJue/MoeJueBlogPic/blob/master/Images/2019/03/30/0072Vf1pgy1g1l3k211blj30ia04x74e.jpg" alt=""> 前段时间一直在做微信相关的业务，虽说不是什么新技术，但之前一直没有机会接触到，然后踩了些坑，抽空整理记录下。<br>
微信支付一共分为7种，分为是：付款码支付、JSAPI支付、Native支付、APP支付、H5支付、小程序支付、人脸支付。<br>
此次业务中使用到的是微信JSAPI支付：用户通过微信扫码、关注公众号等方式进入商家H5页面,并在<strong>微信内</strong>调用 JSSDK完成支付</p>
<p>文档：<a href="https://pay.weixin.qq.com/wiki/doc/api/index.html">https://pay.weixin.qq.com/wiki/doc/api/index.html</a></p>
<p>SDK：[https://pay.weixin.qq.com/wiki/doc/api/micropay.php?chapter=11_1</p>
<p>](<a href="https://pay.weixin.qq.com/wiki/doc/api/micropay.php?chapter=11_1%29JSAPI">https://pay.weixin.qq.com/wiki/doc/api/micropay.php?chapter=11_1)JSAPI</a>支付需要在微信中的浏览器打开才能唤起微信支付，效果如下图<br>
<img src="https://gh-proxy.com/github.com/iAJue/MoeJueBlogPic/blob/master/Images/2019/03/30/0072Vf1pgy1g1l36yn1sej30p91hc40b.jpg" alt=""><br>
附上界面代码<br>
代码中使用了模板引擎<br>
html：</p>
<div class="am-modal-bd">
	<img src="{$competition\['avatar'\]}" alt=""><br>
	<span style="font-size: 13px;color: #72c6ef">{$competition\['username'\]}</span><br>
	<span id="tips" style="font-size: 13px"></span>
  <ul class="ul\_box">
	<li>
		<div></div>
		<div class="label\_box">
			<label>
				<input type="radio" name="price" value="{$prices\[0\]}" checked="">
				<div class="active"><span class="am-icon-diamond"></span> {$prices\[0\]}钻</div>
			</label>
			<label>
				<input type="radio" name="price" value="{$prices\[1\]}">
				<div><span class="am-icon-diamond"></span> {$prices\[1\]}钻</div>
			</label>
			<label>
				<input type="radio" name="price" value="{$prices\[2\]}">
				<div><span class="am-icon-diamond"></span> {$prices\[2\]}钻</div>
			</label>
		</div>
	</li>
	<li>
		<div></div>
		<div class="label\_box">
			<label>
				<input type="radio" name="price" value="{$prices\[3\]}">
				<div><span class="am-icon-diamond"></span> {$prices\[3\]}钻</div>
			</label>
			<label>
				<input type="radio" name="price" value="{$prices\[4\]}">
				<div><span class="am-icon-diamond"></span> {$prices\[4\]}钻</div>
			</label>
			<label>
				<input type="number" name="price" id="price" class="input" placeholder="自定义">
			</label>
		</div>
	</li>
  </ul>
  <span style="font-size: 13px">注：1钻=1元，1钻={$activity\['offset'\]}票</span><br>
  <button type="button" class="am-btn am-btn-primary  am-radius" onclick="callpay()" style="margin-top: 5px;">立即微信支付</button>
</div>
<p>JavaScript：</p>
<p>// 投票
var offset = {$activity[&lsquo;offset&rsquo;]};
$(&rsquo;#tips&rsquo;).html(&lsquo;正在给{$competition[&lsquo;code&rsquo;]}号赠送{$prices[0]}钻=&rsquo;+({$prices[0]}*offset)+&lsquo;票&rsquo;);
$(&rsquo;#vote&rsquo;).click(function(){
$.post(&rsquo;/index/index/detailed.html?cid={$cid}&amp;aid={$aid}&rsquo;,{
formhash :&rsquo;{FORMHASH}&rsquo;,
submit:&lsquo;1&rsquo;,
type:1,
openid:&rsquo;{$_G[&lsquo;member&rsquo;][&lsquo;openid&rsquo;]}&rsquo;
},function(res){
alert(res.msg);
if (res.code == 0) {
$(&rsquo;.box-1 span&rsquo;).text(res.data.all);
$(&rsquo;.box-2 span&rsquo;).text(res.data.rank);
$(&rsquo;.box-3 span&rsquo;).text(res.data.up + &lsquo;票&rsquo;);
}
});
})
/* jQuery对象级别插件扩展 */
$.fn.extend({
/* 单选框 */
hlRadio:function () {
var radioEl=$(this);
radioEl.click(function () {
var price = 0;
price = $(&lsquo;input:radio:checked&rsquo;).val();
$(&rsquo;#price&rsquo;).val(&rsquo;&rsquo;);
$(&rsquo;#tips&rsquo;).html(&lsquo;正在给{$competition[&lsquo;code&rsquo;]}号赠送&rsquo;+price+&lsquo;钻=&rsquo;+(price*offset)+&lsquo;票&rsquo;);
radioEl.siblings(&ldquo;div&rdquo;).removeClass(&ldquo;active&rdquo;);
$(this).siblings(&ldquo;div&rdquo;).addClass(&ldquo;active&rdquo;);
});
},
});
$(&ldquo;input[name=&lsquo;price&rsquo;]&rdquo;).hlRadio();
$(&rsquo;#price&rsquo;).bind(&lsquo;input propertychange&rsquo;, function(){
var price = 0;
price = $(&rsquo;#price&rsquo;).val();
$(&rsquo;#tips&rsquo;).html(&lsquo;正在给{$competition[&lsquo;code&rsquo;]}号赠送&rsquo;+price+&lsquo;钻=&rsquo;+(price*offset)+&lsquo;票&rsquo;);
})</p>
        
        <hr><p>本文2019-03-30首发于<a href='https://zh.moejue.cn/'>阿珏酱のBlog</a>，最后修改于2019-03-30</p>]]>
      </description>
      
        <category>折腾代码</category>
      
    </item>
    
    

    <item>
      <title>Linux下安装PHP环境</title>
      <link>https://zh.moejue.cn/posts/65/</link>
      <pubDate>Mon, 07 May 2018 06:52:32 &#43;0000</pubDate>
      <author>xxx@example.com (MoeJue)</author>
      <guid>https://zh.moejue.cn/posts/65/</guid>
      <description>
        <![CDATA[<h1>Linux下安装PHP环境</h1><p>作者：MoeJue（xxx@example.com）</p>
        
          <p>学习环境：Centos 7.2 正式版_64位</p>
<p># 更新源
yum update</p>
<h1 id="安装nginx">
<a class="header-anchor" href="#%e5%ae%89%e8%a3%85nginx"></a>
安装nginx
</h1><p>yum install nginx -y</p>
<h1 id="安装mysql">
<a class="header-anchor" href="#%e5%ae%89%e8%a3%85mysql"></a>
安装mysql
</h1><p>wget <a href="https://repo.mysql.com//mysql57-community-release-el7-11.noarch.rpm">https://repo.mysql.com//mysql57-community-release-el7-11.noarch.rpm</a>
yum localinstall mysql57-community-release-el7-11.noarch.rpm</p>
<h1 id="安装php72">
<a class="header-anchor" href="#%e5%ae%89%e8%a3%85php72"></a>
安装PHP7.2
</h1><p>rpm -Uvh <a href="https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm">https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm</a>
rpm -Uvh <a href="https://mirror.webtatic.com/yum/el7/webtatic-release.rpm">https://mirror.webtatic.com/yum/el7/webtatic-release.rpm</a>
yum update
yum install -y php72w-cli php72w-common php72w-dba php72w-devel php72w-fpm php72w-gd php72w-imap php72w-mbstring php72w-mysql php72w-pdo php72w-pdo_dblib php72w-pear php72w-pecl-igbinary php72w-pecl-xdebug php72w-process php72w-xml php72w-xmlrpc php72w-opcache php72w-pecl-memcached php72w-pecl-mongodb php72w-pecl-redis</p>
<h1 id="启动服务">
<a class="header-anchor" href="#%e5%90%af%e5%8a%a8%e6%9c%8d%e5%8a%a1"></a>
启动服务
</h1><p>service nginx start
service mysql start
service php-fmp start
/usr/sbin/php-fpm &ndash;nodaemonize &ndash;fpm-config /etc/php-fpm.conf &gt; /dev/null 2&gt;&amp;1 &amp;</p>
        
        <hr><p>本文2018-05-07首发于<a href='https://zh.moejue.cn/'>阿珏酱のBlog</a>，最后修改于2018-05-07</p>]]>
      </description>
      
        <category>教程</category>
      
    </item>
    
    

    <item>
      <title>利用.htaccess绑定子域名到子目录</title>
      <link>https://zh.moejue.cn/posts/58/</link>
      <pubDate>Mon, 22 Jan 2018 01:18:11 &#43;0000</pubDate>
      <author>xxx@example.com (MoeJue)</author>
      <guid>https://zh.moejue.cn/posts/58/</guid>
      <description>
        <![CDATA[<h1>利用.htaccess绑定子域名到子目录</h1><p>作者：MoeJue（xxx@example.com）</p>
        
          <p>一般情况下，一台虚拟主机只允许绑定一个域名到根目录下。<br>
使用过emlog的人 应该对其中的静态链接应该不陌生 它就是典型的利用.htaccess文件来对网页进行域名转向。<br>
利用.htaccess绑定域名到子目录,前提你的空间服务器必须支持apache的rewrite功能，只有这样才能使用.htaccess。如果你的空间是Linux服务器 一般默认都开启了的。即可以实现绑定域名到子目录、一个空间多个站点。</p>
<p>下面是以 link.52ecy.cn 绑定到子目录link为例的.htaccess代码.</p>
<p>&lt;IfModule mod_rewrite.c&gt;<br>
RewriteEngine On<br>
RewriteBase /</p>
<h1 id="绑定link52ecycn-到子目录link">
<a class="header-anchor" href="#%e7%bb%91%e5%ae%9alink52ecycn-%e5%88%b0%e5%ad%90%e7%9b%ae%e5%bd%95link"></a>
绑定link.52ecy.cn 到子目录link
</h1><p>RewriteCond %{HTTP_HOST} ^link\.52ecy\.cn$ [NC]<br>
RewriteCond %{REQUEST_URI} !^/link/<br>
RewriteRule ^(.*)$ link/$1?Rewrite [L,QSA]<br>
#可以绑定多个 只需重复上三行代码并更改一下域名、目录名 就好了<br>
</IfModule></p>
<p>如果你以完成上面的步骤 你的子域名应该可以访问了， 但你会发现在浏览器上访问 主域名+绑定的域名目录 也可以访问，可这并不是我们想要的<br>
接下来我们完成最后一步， 在每一个绑定的目录中 如link目录中 也增加一个 .htaccess 文件 .<br>
htaccess代码如下：</p>
<p>下面是以 music.xmgho.com 绑定到子目录music为例的.htaccess代码.<br>
即可以实现绑定域名到子目录、一个空间多个站点。即可以实现绑定域名到子目录、一个空间多个站点。即可以实现绑定域名到子目录、一个空间多个站点。即可以实现绑定域名到子目录、一个空间多个站点。</p>
<p>&lt;IfModule mod_rewrite.c&gt;<br>
RewriteEngine On<br>
RewriteBase /<br>
#只许绑定的域名访问<br>
RewriteCond %{HTTP_HOST} !^link\.52ecy\.cn$ [NC]<br>
RewriteRule (.*) <a href="http://link.52ecy.cn/$1">http://link.52ecy.cn/$1</a> [L,R=301]<br>
#对绑定目录下与 同名的目录的处理<br>
RewriteCond %{REQUEST_URI} ^\/link\/ [NC]<br>
RewriteCond %{QUERY_STRING} !^(.*)?Rewrite<br>
RewriteRule ^(.*)$ /%{REQUEST_URI}/%{REQUEST_URI}/$1?Rewrite [L,QSA]<br>
</IfModule></p>
        
        <hr><p>本文2018-01-22首发于<a href='https://zh.moejue.cn/'>阿珏酱のBlog</a>，最后修改于2018-01-22</p>]]>
      </description>
      
        <category>折腾代码</category>
      
    </item>
    
  </channel>
</rss>
