Write the Code. Change the World.

8月 27

拼多多开放平台

https://open.pinduoduo.com/

https://jinbao.pinduoduo.com/

https://developers.weixin.qq.com/community/develop/doc/0008a0b4a2c800d7b70a6a68d56400

https://www.sunzhongwei.com/jump-to-pinduoduo-wechat-miniapp

https://open.pinduoduo.com/application/document/browse?idStr=04DD98845AD2977D

多多进宝流程

https://jinbao.pinduoduo.com/third-party/rank

阅读全文 >>

8月 25

vim /> 新买的云,状的是centos8系统,使用起来发现文件内中文乱码。这个得解决。

一步一步往下走

查看你的语言是什么

echo $LANG

# 结果
zh_CN.UTF-8

**继续 **

localectl status

# 结果
   System Locale: LANG=en_US.UTF-8
       VC Keymap: us
      X11 Layout: us

发现系统缺少中文包。弄起来。

yum search Chinese

# 结果
Failed to set locale, defaulting to C.UTF-8
Last metadata expiration check: 3:04:20 ago on Thu Aug 25 10:58:01 2022.
========================================== Name & Summary Matched: chinese ===========================================
ibus-table-chinese.noarch : Chinese input tables for IBus
=============================================== Name Matched: chinese ================================================
ibus-table-chinese-array.noarch : Array input methods
ibus-table-chinese-cangjie.noarch : Cangjie based input methods
ibus-table-chinese-cantonese.noarch : Cantonese input methods
ibus-table-chinese-easy.noarch : Easy input method
ibus-table-chinese-erbi.noarch : Erbi input method
ibus-table-chinese-quick.noarch : Quick-to-learn input methods
ibus-table-chinese-scj.noarch : Smart Cangjie
ibus-table-chinese-stroke5.noarch : Stroke 5 input method
ibus-table-chinese-wu.noarch : Wu pronunciation input method
ibus-table-chinese-wubi-haifeng.noarch : Haifeng Wubi input method
ibus-table-chinese-wubi-jidian.noarch : Jidian Wubi 86 input method, JiShuang 6.0
ibus-table-chinese-yong.noarch : YongMa input method
============================================== Summary Matched: chinese ==============================================
autocorr-zh.noarch : Chinese auto-correction rules
langpacks-zh_CN.noarch : Simplified Chinese langpacks meta-package
langpacks-zh_TW.noarch : Traditional Chinese langpacks meta-package
texlive-arphic.noarch : Arphic (Chinese) font packages
wqy-microhei-fonts.noarch : Compact Chinese fonts derived from Droid

那么,就装个中文包。

dnf install langpacks-zh_CN.noarch

修改本地语言环境。

vim /etc/locale.conf

# 填入
LANG=zh_CN.UTF-8

# 使生效
source /etc/locale.conf

阅读全文 >>

8月 12

某些场景,需要用户的 openid 以及 unionid,如何获取和转换就很有必要。获取公众号所有用户的 openid,通过公众号 openid 获取用户的 unionid。

获取公众号 openid

https://developers.weixin.qq.com/doc/offiaccount/User_Management/Getting_a_User_List.html

# 正常结果 json_decode 下的结构如下
{
  "total":23000,
  "count":10000,
  "data":{"
     openid":[
        "OPENID1",
        "OPENID2",
        ...,
        "OPENID10000"
     ]
   },
   "next_openid":"OPENID10000"
}

通过 openid 获取用户的 unionid

https://developers.weixin.qq.com/doc/offiaccount/User_Management/Get_users_basic_information_UnionID.html#UinonId

阅读全文 >>

8月 09

有些时候,对于并发,我们只想执行一次。多次并发请求就打破了你的想。这里我们用 redis 来弄就好。

操作一波

这里以 laravel 为例

use Illuminate\Support\Facades\Redis;

$time = 60;
$key = 'mimi' . $user->id;
// 如果不存在就 set 值,返回 0 或 1,set 成了返回 1,否则返回 0(表示已经锁住了,不要进去了)
$res = Redis::setnx($key,  $user->id);
if ($res) {
   # 设置 redis 过期(锁的时间秒)
   Redis::expire($key, $time);

   # 你的业务
   xxxxxx
}

laravel 并发处理php 并发处理

阅读全文 >>

7月 28

很多时候,都是终端里看信息。多色的信息就很好看了。我是一个实在人,就从零开始搞一个。其实是别人搞好了,我拿来用。

开始

终端高亮,我们用这个 https://github.com/mgutz/ansi

先建立一个 go 项目

mkdir artisan 
cd artisan 
go mod init artisan

再安装 ansi

go get github.com/mgutz/ansi

然后再封装一个调用方法包

mkdir -p pkg/console
touch pkg/console/console.go

console.go

// Package console 命令行辅助方法
package console

import (
    "fmt"
    "os"

    "github.com/mgutz/ansi"
)

// Success 打印一条成功消息,绿色输出
func Success(msg string) {
    colorOut(msg, "green")
}

// Error 打印一条报错消息,红色输出
func Error(msg string) {
    colorOut(msg, "red")
}

// Warning 打印一条提示消息,黄色输出
func Warning(msg string) {
    colorOut(msg, "yellow")
}

// Exit 打印一条报错消息,并退出 os.Exit(1)
func Exit(msg string) {
    Error(msg)
    os.Exit(1)
}

// ExitIf 语法糖,自带 err != nil 判断
func ExitIf(err error) {
    if err != nil {
        Exit(err.Error())
    }
}

// colorOut 内部使用,设置高亮颜色
func colorOut(message, color string) {
    fmt.Fprintln(os.Stdout, ansi.Color(message, color))
}

最后,新建一个 main.go 然后,调用

touch main.go

package main

import "artisan/pkg/console"

func main() {
    console.Success("多少恨昨夜梦魂中,还似旧时游上苑。车如流水马如龙,花月正春风。")
}

go run main.go

这个时候就可以看到绿色的输出了。

阅读全文 >>