GithubHelp home page GithubHelp logo

yunpian / sms Goto Github PK

View Code? Open in Web Editor NEW
148.0 25.0 91.0 133 KB

云通讯、国际短信、短信API、短信SDK,短信平台,短信验证码,短信接口,短信源码

Java 40.18% JavaScript 3.76% Perl 2.38% Python 29.65% Ruby 2.15% ASP 2.67% C# 4.30% PHP 3.33% C 4.67% C++ 4.67% Go 2.24%

sms's Issues

Golang Captcha Verify Service

type Result struct {
	Code int `json:"code"`
	Msg string `json:"msg"`
}

func CaptchaVerify(token, authenticate string) (resp *Result, err error) {
	confMap := url.Values{}

	confMap.Add("authenticate", authenticate)
	confMap.Add("token", token)

	confMap.Add("captchaId", "YourCaptchaId")
	confMap.Add("secretId", "YourSecretId")
	confMap.Add("version", "1.0")

	nowTime := time.Now().UnixNano()
	confMap.Add("timestamp", fmt.Sprintf("%v", nowTime / 1e6))  // ms

	rand.Seed(nowTime)
	confMap.Add("nonce", fmt.Sprintf("%v", rand.Intn(99999) + 1))

	// generate signatureStr
	keys := make([]string, 0)
	for k, _ := range confMap {
		keys = append(keys, k)
	}
	sort.Strings(keys)
	signatureStr := ""
	for _, k := range keys {
		signatureStr += k
		signatureStr += confMap[k][0]
	}
	secretKey := "YourSecretKey"
	signatureStr += secretKey

	// generate signatureMd5
	md5Ctx := md5.New()
	md5Ctx.Write([]byte(signatureStr))
	confMap.Add("signature", hex.EncodeToString(md5Ctx.Sum(nil)))

	// PostForm
	req, err := http.PostForm("https://captcha.yunpian.com/v1/api/authenticate", confMap)
	if err != nil {
		return nil, err
	}
	defer req.Body.Close()

	body, err := ioutil.ReadAll(req.Body)
	if err != nil {
		return nil, err
	}

	var res Result
	if err = json.Unmarshal([]byte(body), &res); err != nil {
		return nil, err
	}
	return &res, nil
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.