golang实现微信公众号发红包功能

微信公众号发送红包(源码) //A推荐了B,1.如果B成功支付,2.如果B来源为雅思哥给A发66.66,如果不是雅思哥发200 //在活动期间,当A推荐了B时,A不会有任何的增加积分的操作,只可以领取红包(积分加0),活动结束之后领取红包功能下线后,再有推荐即可增加积分 //B: $_GET[‘userid’] //A: $_GET[‘tui_userid’] //开启红包 function pay(url,url,url,... 阅读详情

ps:在读代码前一定要先阅读微信公众号发红包官方文档:

https://pay.weixin.qq.com/wiki/doc/api/tools/cash_coupon.php?chapter=13_4&index=3


以下是代码实现,

package server

import (
	"crypto/tls"
	"fmt"
	"io/ioutil"
	"crypto/x509"
	"net/http"
	"bytes"
	"strings"
	"sort"
	"reflect"
	"time"
	"math/rand"
	"strconv"
	"encoding/xml"
	"github.com/alecthomas/log4go"
	"crypto/md5"
	"encoding/hex"
)

var _tlsConfig *tls.Config
var (
	weixinPayKey="19200bbb0b4c09247ec02edce69f6ddd"   //微信密钥
	weixinMchId = "10000098"  //微信商户号
	wechatUrl = "https://api.mch.weixin.qq.com/mmpaymkttransfers/sendredpack"  //请求发红包的地址
	formatDate = "20060102"
	xmlStr = "xml"
	RedPacketRequestStr = "RedPacketRequest"
	strWeixinAppId =            "wx8888888888888888"         //公众账号ID
	strWeixinClientCertPemPath = "/home/apiclient_cert.pem"  //客户端证书存放绝对路径
	strWeixinClientKeyPemPath = "/home/apiclient_key.pem"    //客户端私匙存放绝对路径
	strWeixinRootCaPath = "/home/rootca.pem"                 //服务端证书存放绝对路径
)

type WeixinSendRedPacket struct {

}


//发红包的请求实体
type RedPacketRequest struct {
	ActName  	string      `xml:"act_name"`	  //必填,活动名称
	ClientIp 	string 		`xml:"client_ip"`	  //必填,调用接口的机器ip地址
	MchBillno 	string  	`xml:"mch_billno"`   //必填,商户订单号
	MchId    	string		`xml:"mch_id"`       //必填,微信支付分配的商户号
	NonceStr  	string  	`xml:"nonce_str"`    //必填,随机字符串,不超过32位
	ReOpenid  	string   	`xml:"re_openid"`	  //必填,接收红包者用户,用户在wxappid下的openid
	Remark		string      `xml:"remark"`		  //必填,备注信息
	SendName  	string		`xml:"send_name"`    //必填,红包发送者名称
	TotalAmount int		  	`xml:"total_amount"` //必填,付款金额,单位为分
	TotalNum    int 		`xml:"total_num"`    //必填,红包发放人数
	Wishing     string 		`xml:"wishing"`      //必填,红包祝福语
	Wxappid  	string		`xml:"wxappid"`      //必填,微信公众号id
	Sign      	string  	`xml:"sign"`		  //必填,签名
	//SceneId		string		`xml:"scene_id"`	  //非必填,红包使用场景
	//RiskInfo 	string		`xml:"risk_info"`    //非必填,用户操作的时间戳
	//ConsumeMchId string		`xml:"consume_mch_id"` //非必填,资金授权商户号
}



//发微信红包
func (*WeixinSendRedPacket)SendRedPack(redPacketEntity *RedPacketRequest) (*http.Response, error) {
	nonce_str,_ := getUUID()   //随机字符串

	//订单号,随机生成
	r := rand.New(rand.NewSource(time.Now().UnixNano()))
	mch_billno:=weixinMchId + time.Now().Format(formatDate) + strconv.FormatInt(time.Now().Unix(), 10)[4:]+strconv.Itoa(r.Intn(8999) + 1000)

	redPacketEntity.NonceStr=nonce_str
	redPacketEntity.MchBillno=mch_billno
	redPacketEntity.MchId=weixinMchId
	redPacketEntity.Wxappid = strWeixinAppId
	// 生成签名
	sign := strings.ToUpper(signature(*redPacketEntity)) //签名
	redPacketEntity.Sign=sign

	data, err := xml.MarshalIndent(redPacketEntity, "", "   ")

	if err!=nil {
		log4go.Error(err)
		return nil,err
	}
	sendData:=strings.Replace(string(data), RedPacketRequestStr , xmlStr ,-1)

	fmt.Println(sendData)
	//POST数据
	return securePost(wechatUrl, []byte(sendData))
}

//加载微信发红包需要的证书
func getTLSConfig() (*tls.Config, error) {
	if _tlsConfig != nil {
		return _tlsConfig, nil
	}

	// load cert
	cert, err := tls.LoadX509KeyPair(strWeixinClientCertPemPath, strWeixinClientKeyPemPath)
	if err != nil {
		fmt.Println("load wechat keys fail", err)
		return nil, err
	}

	// load root ca
	caData, err := ioutil.ReadFile(strWeixinRootCaPath)
	if err != nil {
		fmt.Println("read wechat ca fail", err)
		return nil, err
	}
	pool := x509.NewCertPool()
	pool.AppendCertsFromPEM(caData)

	_tlsConfig = &tls.Config{
		Certificates: []tls.Certificate{cert},
		RootCAs:      pool,
	}
	return _tlsConfig, nil
}

//http发送请求
func securePost(url string, xmlContent []byte) (*http.Response, error) {
	tlsConfig, err := getTLSConfig()
	if err != nil {
		return nil, err
	}

	tr := &http.Transport{TLSClientConfig: tlsConfig}
	client := &http.Client{Transport: tr}

	return client.Post(
		url,
		"text/xml",
		bytes.NewBuffer(xmlContent))
}


//签名算法
func signature(sendParamEntity interface{}) string {
	str:=getFieldString(sendParamEntity)
	if str!=""{
		str=fmt.Sprintf("%s&%s=%s",str,"key",weixinPayKey)
		fmt.Println(str)
		md5Ctx2 := md5.New()
		md5Ctx2.Write([]byte(str))
		str = hex.EncodeToString(md5Ctx2.Sum(nil))

		return str
	}else{
		return ""
	}
}

//获取结构体字段及值的拼接值
func getFieldString(sendParamEntity interface{}) string {
	m:=reflect.TypeOf(sendParamEntity)
	v:=reflect.ValueOf(sendParamEntity)
	var tagName string
	numField:=m.NumField()
	w:=make([]string,numField)
	numFieldCount:=0
	for i := 0; i < numField; i++ {
		fieldName:=m.Field(i).Name
		tags := strings.Split(string(m.Field(i).Tag), "\"")
		if len(tags) > 1 {
			tagName = tags[1]
		} else {
			tagName = m.Field(i).Name
		}

		fieldValue:=v.FieldByName(fieldName).Interface()

		if fieldValue!=""  {
			s:=fmt.Sprintf("%s=%v",tagName,fieldValue)
			w[numFieldCount]=s
			numFieldCount++
		}
	}
	if numFieldCount==0{
		return ""
	}
	w = w[:numFieldCount]
	sort.Strings(w)
	return strings.Join(w,"&")
}

//获取uuid
func getUUID() (string, error) {
	uuid := make([]byte, 16)
	n, err := rand.Read(uuid)
	if n != len(uuid) || err != nil {
		return "", err
	}
	uuid[8] = 0x80 // variant bits see page 5
	uuid[4] = 0x40 // version 4 Pseudo Random, see page 7

	return hex.EncodeToString(uuid), nil
}


golang支付:微信公众号,微信应用,微信小程序,微信企业支付,支付宝网页版,支付宝应用,支付宝企业支付- milkbobo / gopay golang支付:微信公众号,微信应用,微信小程序,微信企业支付,支付宝网页版,支付宝应用,支付宝企业支付- milkbobo / gopay-源码 立即下载

相关推荐

编译原理2024期末复习(面向做题,大题速学)【太原理工大学】

归约-归约”冲突就是在项目集规范族一个状态中两个。

m0_63181421的博客 1万+

别再问用 Go 语言如何对接微信支付了:看看这个包

点击上方蓝色“Go语言中文网”关注我们,领全套Go资料,每天学习Go语言作为开发人员,微信生态我们不能无视,微信提供的开放能力,我们应该有所了解。微信支付作为重要的一部分,平时工作中...

轩脉刃的刀光剑影 2012

【fMRI实战】从fALFF/ReHo双样本t检验到GRF矫正:DPABI结果可视化与报告全流程

本文详细介绍了使用DPABI进行fMRI数据分析的全流程,包括fALFF/ReHo双样本t检验、GRF多重比较矫正、结果可视化与报告。重点讲解了DPABI Viewer的操作技巧、GRF参数设置要点、脑区定位方法以及结果提取与可视化技巧,帮助研究者高效完成fMRI数据分析与报告。

weixin_32612263的博客 420

golang 微信支付介绍

golang微信支付介绍

虚月的专栏 6705

PyTorch实战:手把手教你用QAT量化感知训练拯救模型精度(附避坑指南)

本文详细介绍了如何使用PyTorch进行QAT量化感知训练,以提升模型在边缘设备上的推理精度。通过核心原理讲解、实战代码示例和避坑指南,帮助开发者掌握从环境配置、模型训练到边缘部署的全流程,有效解决传统量化方法导致的精度损失问题。

c7d8e的博客 330

NRF52832串口通信避坑指南:从SDK配置到硬件流控(RTS/CTS)实战

本文详细介绍了NRF52832串口通信的实战指南,从SDK配置到硬件流控(RTS/CTS)的完整实现。通过分析UARTE模块特性、解决SDK版本差异问题、正确配置硬件引脚以及实现稳定通信的代码示例,帮助开发者避开常见陷阱,确保高效可靠的串口通信。特别强调了硬件流控在高速通信中的重要性及其实践方法。

weixin_33739646的博客 283

golang后端php前端,前端php加后端golang微信发红包

package mainimport ("bytes""crypto/md5""crypto/tls""crypto/x509""encoding/hex""encoding/xml""fmt""github.com/garyburd/redigo/redis""io/ioutil""log""math/rand""net/http""os""runtime""strconv""strings""...

weixin_42128315的博客 171

Sparse-ICP—(4) 加权稀疏迭代最近点算法(matlab版)

本文介绍了加权稀疏迭代最近点算法的实现。

点云侠的博客 646

研究微信红包分配算法之Golang版

今天来看一下红包的分配,参考几年前流传的微信红包分配算法,今天用Golang实现一版,并测试验证结果。微信红包的随机算法是怎样实现的?

u010401880的专栏 754

Android 11多窗口+分屏+APP窗口嵌套TaskView实现原理一

然而随着版本的迭代升级,google对分屏的定制差异化也越来越大,Androd 11的分屏用的是split-screen-primary和split-screen-secondary的方式,在systemui中去实现的,其定制化的灵活度不是很高,很多业务都是放到sustemui或者fw去实现,但是随着版本的升高,后面出现了TaskView来替代了老版本的分屏方式,但是Task的核心原理其实和之前的方式是一样的,TaskView来实现分屏。

qq_18420641的博客 2618

(三十九)Flask 多应用架构(Multiple Apps)与 DispatcherMiddleware 实战解析

(三十九)Flask 多应用架构(Multiple Apps)与 DispatcherMiddleware 实战解析

孤寒者的博客 1万+

golang实现微信公众号发送代金券及获取代金券的功能

ps:在读代码前一定要先阅读微信公众号发红包官方文档: https://pay.weixin.qq.com/wiki/doc/api/tools/sp_coupon.php?chapter=12_3&index=4 package server import ( "time" "math/rand" "strconv" "strings" "github.com/a

skh2015java的博客 2017

基于 MATLAB 的精馏塔模拟仿真

基于 MATLAB 的精馏塔模拟仿真精馏塔是一种重要的化工设备,其中乙烯精馏塔和醋酸乙烯精馏塔是常见的两种精馏塔。本文基于 MATLAB 软件,给出了针对这两种精馏塔的模拟仿真代码。

与其临渊羡鱼,不如退而结网 905

9 月编程语言排行榜发布,Python 一枝独秀

点击上方“民工哥技术之路”选择“星标”每天10点为你分享不一样的干货读者福利!多达 2048G 各种资源免费赠送转自:oschinaPYPL(PopularitY of...

民工哥的博客 426

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

【程序员1024狂欢节幕后揭秘】:深度解析年度最火技术社群活动运营策略

揭秘程序员社群1024活动成功运营的五大策略,涵盖线上线下联动、技术分享与福利激励机制,适用于各类技术社群年度活动策划。通过精准用户运营与内容设计提升参与度,实现品牌曝光与成员粘性双赢,值得收藏。

Instrustar的博客 1061

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

编程的一些经验分享Tips

分享 -为什么我来分享。胡总问我有没有重之前的培训中学到什么,我随口说了句,对我没有太大用,然后就不解释了。当然不能怂啊,讲就讲啊。 -能get到一个点就是收获。大家也分享一些好的东西。 -分享的有些大家知道,也有不知道的。 -尽量不讲理论性的东西。什么兴趣是最好的老师啊, -工程师有比较会学习,不学就会被淘汰。我工作经验不多,能分享的经验也比较有限,体谅。 -让大家发言,张枭如何学习reac...

weixin_33874713的博客 76

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

GO微服务实战之红包系统

业务模型 2-3 红包数据库表结构讲解 红包序列 红包算法 红包算法逻辑6点要求 微信两倍平均算法

王大阳的博客 775

微信企业给用户付款接口,golang版

企业付款至用户微信支付零钱或银行卡 本文主要讲 微信企业付款到用户零钱的接口: 应用场景 代码 提醒 坑 总结 应用场景 二次开发红包,用户抢到红包金额,需要通过企业付款到用户的零钱包或者直接打到用户的卡。分销提成 提现。以及给用户退款等。 代码 主要参考文档 —— [ 微信官方文档-企业付款 ] 代码块 我这边提取了两个重要的文件,一个是

蚂蚁爱吃糖 7076

redis配合golang实现简单的抢红包功能

抢红包功能是一个比较重要的功能,在分布式环境中,需要考虑使用redis或etcd等缓存中间件来实现。 1.使用redis中的`set`实现 2.在lua脚本中处理保证一致性 3.每抢一个红包就从set中捞取一个值 4.最终一致性由关系数据库保证 5.防止重复从关系数据库加载未抢数据,在抢完后把set删除添加同名string值

a34ErxV的博客 401

微信公众号给用户发红包

微信官方文档 https://pay.weixin.qq.com/wiki/doc/api/tools/cash_coupon.php?chapter=13_3&index=2 一、准备工作 1、开通现金红包功能。操作路径:【登录微信支付商户平台——>产品中心——>现金红包——>开通】 2、商户调用微信红包接口时,服务器会进行证书验证,请在商户平台下载证书 3、在发放现...

dlorwolleh的博客 992

Go代码实现 拼手气红包(二倍均值法)

拼手气红包

带着笑或是很沉默。 1065

【微软面试题】golang实现红包金额随机分配

问题 有一次参见微软面试,在第三面技术面的时候,面试官给了如下一道算法题: Split money in red envelop. Given amount S, split into N random numbers. For example: Input: S=100 N=3 Output: [40.00 25.03 34.97] 分析 场景 这是一道模拟抢红包的场景,有一个总额为S的红包,有N个人抢,每个人抢到的金额随机,且总额为S。 隐藏点 目前红包最小单位为分,因此最终得到的浮点数精度为2位小

sym的博客 1103

微信拼手气红包实现(Go,腾讯面试题)

腾讯面试题《微信拼手气红包》的Go解决方案。

TCatTime的博客 1576

Go实战抢红包系统(四) - 基础实施层coding

软件项目中的基础设施就像是征战中的神兵利器。本章介绍Golang项目应具备基础设施,完整的业务系统应该需要的基础设施资源,在没有Java Spring全家桶那样的明星级框架情况下,让Golang项目轻松自如管理基础资源的生命周期、构建和使用基础资源。 … 1 重在设计 go中使用枚举值 1.1 定义常数实现枚举 ◆ 类型别名的形式来声明类型 ◆ iota来自增和自动赋值 const ( St...

JavaEdge全是干货的技术号 2387
上一篇: Java集合类源码详解
下一篇: golang实现微信公众号发送代金券及获取代金券的功能
思维的深度
博客等级 码龄11年 2万+粉丝 391原创
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值