越南zalo 登录接入 其他

一、准备工作

0、创建zalo 的oa 账号
https://oa.zalo.me/home
里面涉及到官方的公众号的申请,需要本地人的企业资质等信息,这个过程和微信的基本一致,需要实名认证

1、域名验证
https://developers.zalo.me/app/1350607824639156579/verify-domain
2、官方账号绑定

https://developers.zalo.me/app/1350607824639156579/oa/manage

二、开发

官方账户api调用
https://developers.zalo.me/docs/sdk/php-sdk/tai-lieu/official-account-api

use Zalo\\Zalo;

// 1、生成登录链接
$config = array(
    'app_id' => '1234567890987654321',
    'app_secret' => 'AbC123456XyZ'
);
$zalo = new Zalo($config);

$helper = $zalo -> getRedirectLoginHelper();
$callbackUrl = "https://www.callbackack.com";
$codeChallenge = "your code challenge";
$state = "your state";
$loginUrl = $helper->getLoginUrl($callBackUrl, $codeChallenge, $state);

// 2、回调的函数头部插入以下代码,获取token
$codeVerifier = "your code verifier";
$zaloToken = $helper->getZaloToken($codeVerifier); // get zalo token
$accessToken = $zaloToken->getAccessToken();

// 3、通过token获取其他信息
$accessToken = 'put_your_access_token_here';
$params = ['fields' => 'id,name,picture'[];
$response = $zalo->get(ZaloEndpoint::API_GRAPH_ME, $accessToken, $params);
$result = $response->getDecodedBody(); // result

艾文 发布于  2024-4-23 14:53 

chrome 插件开发记录 编程学习

1、chrome plugin 2.0

2、chrome plugin 3.0


艾文 发布于  2024-4-21 18:29 

艾文 发布于  2024-3-30 20:23 

vscode 远程 linux开发 工具使用

1、配置
vscode按照sftp扩展,并配置文件:/my-proj/.vscode/sftp.json

{
    "name": "192.18.9.149",
    "host": "192.18.9.149",
    "protocol": "sftp",
    "port": 22,
    "username": "myname",
    "password": "mypwd",
    "remotePath": "/home/aiwen/my-proj/",
    "uploadOnSave": true
}

艾文 发布于  2024-3-27 14:22 

艾文 发布于  2024-3-6 22:27 

ubuntu 系统的使用记录 工具使用

一、配置使用

1、虚拟机内只有127.0.0.1的回环地址
如果在 VMware 上运行的 Ubuntu 虚拟机中执行 ifconfig 只显示 127.0.0.1(即回环地址),而没有其他网络接口的IP地址,可能有几个原因导致这种情况。以下是一些建议的步骤,帮助你解决这个问题:


sudo service networking restart
sudo systemctl status open-vm-tools
sudo dhclient -v
ifconfig

2、代理配置

git config --global http.proxy http://172.18.9.88:1080
git config --global https.proxy http://172.18.9.88:1080

#如果要取消代理

git config --global --unset http.proxy
git config --global --unset https.proxy

这个是git的设置代理,地址是你本地的ip+端口
# 可以给设置curl的代理:
export HTTPS_PROXY=http://172.18.9.88:1080
export HTTP_PROXY=http://172.18.9.88:1080
使用配置文件

为wget使用代理,可以直接修改/etc/wgetrc,也可以在主文件夹下新建.wgetrc,并编辑相应内容,本文采用后者。

将/etc/wgetrc中与proxy有关的几行复制到~/.wgetrc,并做如下修改:

#You can set the default proxies for Wget to use for http, https, and ftp.
# They will override the value in the environment.
https_proxy = http://172.18.9.88:1080/
http_proxy = http://172.18.9.88:1080/
ftp_proxy = http://172.18.9.88:1080/

# If you do not want to use proxy at all, set this to off.
use_proxy = on

二、开发使用

1、略


艾文 发布于  2024-3-6 14:29 

web3安全汇集 安全

一、风险项

二、工具集

三、其他


艾文 发布于  2024-3-6 11:17 

ubuntu 上开发solana合约记录 web3

一、环境搭建

 1、安装虚拟机

 2、vm远程开启ssh链接 (参考:https://blog.csdn.net/qq_45164331/article/details/122533327#)

打开终端并安装openssh-server软件包

sudo apt update
sudo apt install openssh-server

出现提示时,输入密码,然后按Enter继续安装。
安装完成后,SSH服务将自动启动。您可以通过键入以下命令来验证SSH是否正在运行:

sudo systemctl status ssh

输出应告诉您该服务正在运行,并已启用以在系统引导时启动:

ssh.service - OpenBSD Secure Shell server
 Loaded: loaded (/lib/systemd/system/ssh.service; enabled; vendor preset: enabled)
 Active: active (running) since Mon 2020-06-01 12:34:00 CEST; 9h ago

按q返回到命令行提示符,如果运行状态不为active(running),需要手动开启,命令为:

/etc/init.d/ssh start

3、开发环境配置

设置wget代理:
sudo vi /etc/wgetrc

设置curl代理 == 运行命令( solana-install update 也需要这个代理)
export HTTPS_PROXY=http://172.18.9.88:1080
export HTTP_PROXY=http://172.18.9.88:1080

#备注:设置git的代理:
sudo apt-install git

git config --global http.proxy http://172.18.9.88:1080
git config --global https.proxy http://172.18.9.88:1080

#如果要取消代理

git config --global --unset http.proxy
git config --global --unset https.proxy
  • 安装rust
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
  • 安装Solana CL
# 注意这个要需要代理(上面准备的代理):
sh -c "$(curl -sSfL https://release.solana.com/stable/install)"
solana --version
  • 安装 avm
cargo install --git https://github.com/coral-xyz/anchor avm --locked --force
avm install latest
avm use latest

二、开发hello word 合约并部署

[http]
proxy = "http://127.0.0.1:1080"

[https]
proxy = "http://127.0.0.1:1080"

注意:替换为实际的代理服务器地址和端口。

1、初始化工程和代码

  • 工程创建
    cargo init hello_world --lib
    cd hello_world
    cargo add solana-program  
solana program deploy ./target/deploy/hello_world.so
Program Id: 3J36G34bRfgqmwMKQDY7entAEs1vGi5uhG3935rHpnw4
  • 代码编写
    合约代码编辑: src/lib.rs
use solana_program::{
    account_info::AccountInfo, entrypoint, entrypoint::ProgramResult, msg,
    program_error::ProgramError, pubkey::Pubkey,

};

entrypoint!(process_instruction);
fn process_instruction(
    _program_id: &Pubkey,
    _accounts: &[AccountInfo],
    data: &[u8],
) -> ProgramResult {
         msg!("Hello, world!");

    // we can split first byte as selector
    let (&instruction, _rest) = data
        .split_first()
        .ok_or(ProgramError::InvalidInstructionData)?;

    match instruction {
        1 => {
            msg!("here is instruction 1");
        }
        2 => {
            msg!("here is instruction 2");
        }
        _ => {
            msg!("no such instruction");
            return Err(ProgramError::InvalidInstructionData);
        }
    }
    Ok(())
}

2、构建代码部署代码


#构建 -- 注意这个环节会遇到【问题1】
cargo build-bpf  

#部署
solana program deploy ./target/deploy/hello_world.so
Program Id: 3J36G34bRfgqmwMKQDY7entAEs1vGi5uhG3935rHpnw4

注意:如果要重新部署合约,需要去 /home/aiwen/Documents/solana-proj/hello_world/target/deploy目录把程序的programID对应的keypair 删除,然后自己重新用keypair工具生成一个或者直接部署即可(部署工具会自动生成一个地址)

3、客户端交互代码(可以是本地控制台也可以是网页的--统称客户端):

编写js代码(CommonJS):

const solanaWeb3 = require("@solana/web3.js");

const {
  sendAndConfirmTransaction,
  clusterApiUrl,
  Connection,
} = require("@solana/web3.js");

const {
  Keypair,
  Transaction,
  SystemProgram,
  LAMPORTS_PER_SOL,
} = require("@solana/web3.js");

async function runMain() {
  try {
    //console.log(solanaWeb3);
    let keypair = Keypair.generate();

    console.log('keypair.publicKey==> ', keypair.publicKey);

    let fromKeypair = Keypair.generate();
    let toKeypair = Keypair.generate();
    let transaction = new Transaction();

    // 私钥的uint8 字符串,solana genkeypair 可以生成类似的
    let solSecret = [45,19,193,xxxxxxxxxxxxxxxxxxxxxxxxxxx,63,147];
    let secretKey = Uint8Array.from(solSecret);
    fromKeypair = Keypair.fromSecretKey(secretKey);

    await transaction.add(
      SystemProgram.transfer({
        fromPubkey: fromKeypair.publicKey,
        toPubkey: toKeypair.publicKey,
        lamports: LAMPORTS_PER_SOL,
      }),
    );

    let connection = new Connection("http://172.18.9.65:8899");
    // connection = new Connection(clusterApiUrl("devnet"));
    //sendAndConfirmTransaction(connection, transaction, [fromKeypair]);
    let  balance = await connection.getBalance(fromKeypair.publicKey);
    console.log('Balance:', fromKeypair.publicKey,balance , balance / LAMPORTS_PER_SOL, 'SOL');
    balance =  await connection.getBalance(fromKeypair.publicKey);
    console.log(` balance: ${balance / 10**9} SOL`);
    testMemo(connection, fromKeypair);

  } catch (error) {
    console.error('Error connecting to wallet:', error);
  }
}
function testMemo(connection, account){
    const instruction = new solanaWeb3.TransactionInstruction({
        keys: [],
        programId:new solanaWeb3.PublicKey('BJPN5RF2b3n4bW7Pqc4cTei2Fv5ij1nQtFYENhvj6CpQ'),
        data: Buffer.from(new Uint8Array([2])), // data   Buffer.from('cztest'),
    });
    console.log("account:", account.publicKey.toBase58())
   solanaWeb3.sendAndConfirmTransaction(
    connection,
    new solanaWeb3.Transaction().add(instruction),
    [account],
    {
        skipPreflight: true,
        commitment: "singleGossip",
    },
).then((result) => {
    // 事务成功时的处理逻辑,返回是这个哈希值
    console.log("Transaction successful:", result);
}).catch((error) => {
    // 事务失败时的处理逻辑
    console.error("Transaction failed:", error);
});}
// Run the example
runMain();

运行这个node hello.js :

Transaction successful: 24wfgDpSB9kgVALC9HsPEj2y8SgvEofjUUSBmsNmxbyiy6v6k5KPq93QZe7117EQkDTMEbE7xFCJVt8c7sQT7bfu

去控制台查看合约执行的输出日志:
solana confirm -v 24wfgDpSB9kgVALC9HsPEj2y8SgvEofjUUSBmsNmxbyiy6v6k5KPq93QZe7117EQkDTMEbE7xFCJVt8c7sQT7bfu

输出结果:
PC URL: http://172.18.9.65:8899
Default Signer Path: /home/aiwen/Documents/solana-proj/id.json
Commitment: confirmed

Transaction executed in slot 252641:
  Block Time: 2024-03-02T09:18:17+08:00
  Version: legacy
  Recent Blockhash: AeQTKpjbZ6fCEzWyb1uyihvExB3vBJKCqNaeCCbSSjug
  Signature 0: 24wfgDpSB9kgVALC9HsPEj2y8SgvEofjUUSBmsNmxbyiy6v6k5KPq93QZe7117EQkDTMEbE7xFCJVt8c7sQT7bfu
  Account 0: srw- asdfpLg3rU76AjasdfNBb2RR5GsL7ECa (fee payer)
  Account 1: -r-x BJPN5RF2b3n4bW7Pqc4cTei2Fv5ij1nQtFYENhvj6CpQ
  Instruction 0
    Program:   BJPN5RF2b3n4bW7Pqc4cTei2Fv5ij1nQtFYENhvj6CpQ (1)
    Data: [2]
  Status: Ok
    Fee: ◎0.000005
    Account 0 balance: ◎499999993.7501871 -> ◎499999993.7501821
    Account 1 balance: ◎0.00114144
  Log Messages:
    Program BJPN5RF2b3n4bW7Pqc4cTei2Fv5ij1nQtFYENhvj6CpQ invoke [1]
    Program log: Hello, world!
    Program log: here is instruction 2
    Program BJPN5RF2b3n4bW7Pqc4cTei2Fv5ij1nQtFYENhvj6CpQ consumed 254 of 200000 compute units
    Program BJPN5RF2b3n4bW7Pqc4cTei2Fv5ij1nQtFYENhvj6CpQ success

Confirmed

3、遇到问题解决

问题1、rust 环境和solana-program的不匹配

  • 报错日志
执行命令:
cargo build-bpf
执行日志:
error: package `solana-program v1.18.3` cannot be built because it requires rustc 1.72.0 or newer, while the currently active rustc version is 1.68.0-dev
Either upgrade to rustc 1.72.0 or newer, or use
cargo update -p solana-program@1.18.3 --precise ver
where `ver` is the latest version of `solana-program` supporting rustc 1.68.0-dev
cargo-build-sbf  # 用命令行查看当前需要的
solana-cargo-build-sbf 1.17.6
platform-tools v1.37
rustc 1.68.0  #应该是要这个版本的rust

如果之前已经安装了 rustup,请确保更新到最新版本:

rustup self update

安装 Rust 1.68.0:

rustup toolchain install  1.68.0

切换到安装的 Rust 版本:

rustup default 1.68.0

现在,你的系统上就安装了 Rust 1.68.0 版本。你可以通过运行以下命令验证版本:

rustc --version

#查看当前所有版本
rustup show

确保环境变量中包含 ~/.cargo/bin 目录,这样你就可以在终端中直接运行 Rust 工具。

请注意,rustup 工具允许你轻松切换和管理多个 Rust 版本。如果你需要在不同的项目中使用不同的 Rust 版本,rustup 是一个方便的工具。

之后:

方案1(已验证):
solana-install init 1.18.1

方案2:
#可以强制安装使用的工具
cargo-build-sbf --force-tools-install

附录

wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.34.0/install.sh | bash
nvm --version
nvm ls-remote

nvm install  v18.19.1
nvm ls
nvm use v18.19.1

参考资料

1、https://docs.solanalabs.com/cli/install


艾文 发布于  2024-3-1 18:44 

centos 常用命令记录 工具使用

基础配置

  • 1、centos yum源配置,执行3个命令:
cd /etc/yum.repos.d/
mkdir backup && mv CentOS-Linux-*.repo backup
wget -O /etc/yum.repos.d/CentOS-Linux-Base-ali.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
  • 2、修改密码
sudo passwd root

艾文 发布于  2024-2-28 22:25 

千万级用户大规模并发系统设计开发 web开发

背景

  • 越南、用户投票、千万级用户
  • 服务器负载

支付通道

  • 越南支付选型:
    目前选择(MoMo Pay支付平台)
    开发文档: https://developers.momo.vn/v3/docs/payment/api/wallet/pay-with-token

  • MoMo Pay:

    MoMo是越南最大的移动支付和商务平台,类似于中国的支付宝。
    成立于2007年,MoMo的电子钱包和支付应用程序允许用户在全国范围内进行现金支付、付款、手机充值、购买软件许可、网游点卡、机票和电影票等。
    MoMo与20多家金融机构合作,包括越南本土银行和国际支付公司(如JCB、万事达卡和Visa)。
    MoMo服务超过1000万越南用户,尤其在金融服务缺位的农村地区1。

  • Zalo Pay:

    Zalo Pay是一款功能丰富的移动支付应用程序,专为生活和商业需求中的付款而设计。
    用户可以将卡与Zalo Pay连接,进行转账、支付和管理钱包。
    Zalo Pay于2016年正式在越南推出,类似于微信支付,适用于所有Zalo用户。
    近期,由于Zalo Pay封号严重,许多越南人转向了MoMo Pay1。

  • PrincePay:

    PrincePay是另一个越南的支付平台,可以帮助外国人从银行转账到越南账户。
    即使在不接受信用卡的小咖啡店或小超市,也可以使用PrincePay。
    PrincePay还可以帮助你从银行转账到你的账户,方便支付业务1。

架构设计

参考1: 数据库能抗多大并发压力 https://juejin.cn/post/7086247223750721572
参考2:redis的并发性能 https://zhuanlan.zhihu.com/p/383886868

1、配置需求

  • web服务器2核4G内存 x 10台
    单台并发承载 3000
    单请求平均10KB
    同时并发总流量: 10K * 3000

  • mysql数据库服务器配置
    8核16G的数据库每秒大概可以抗多少并发压力?大体上来说,在几千这个数量级

  • redis缓存服务器配置

    参考: Redis单机性能测试&压力并发测试 https://blog.csdn.net/sishenhzy/article/details/100918712

$redis-benchmark -r 1000000 -n 2000000 -t get,set,lpush,lpop -P 16 -q

$redis-benchmark -n 1000000 -t set,get -P 16 -q
SET: 403063.28 requests per second
GET: 508388.41 requests per second

附录

1、负载均衡测试:评估系统性能和可靠性的关键 https://blog.csdn.net/m0_50892002/article/details/135612510


艾文 发布于  2024-2-19 15:05