Apply .gitignore rules

This commit is contained in:
皮蛋13361098506
2025-01-06 16:21:36 +08:00
parent 1b77f62820
commit ccd2c530cf
580 changed files with 69806 additions and 0 deletions

View File

@@ -0,0 +1,48 @@
package validationUtil
import "regexp"
var (
// 身份证号
re_idno = regexp.MustCompile("^[1-9]{1}[0-9]{14}$|^[1-9]{1}[0-9]{16}([0-9]|[xX])$")
// 邮箱
re_email = regexp.MustCompile(`^[0-9A-Za-z][\.-_0-9A-Za-z]*@[0-9A-Za-z]+(\.[0-9A-Za-z]+)+$`)
// 中国手机号验证
re_chinesePhoneNum = regexp.MustCompile(`^1(3[0-9]|4[57]|5[0-35-9]|7[0135678]|8[0-9])\d{8}$`)
)
// 验证身份证号码
// idno:身份证号
// 返回值:
// bool: true:成功 false:不合法
func IsValideIdno(idno string) bool {
if re_idno.MatchString(idno) {
return true
}
return false
}
// 验证邮箱
// email:邮箱
// 返回值:
// bool: true:成功 false:不合法
func IsValideEmail(email string) bool {
if re_email.MatchString(email) {
return true
}
return false
}
// 验证中国的手机号码
// phoneNum:待验证的手机号码
// 返回值:
// bool: true:成功 false:不合法
func IsValideChinesePhoneNum(phoneNum string) bool {
if re_chinesePhoneNum.MatchString(phoneNum) {
return true
}
return false
}

View File

@@ -0,0 +1,82 @@
package appChargeUtil
import (
"errors"
"fmt"
"goutil/webUtil"
)
const (
con_SandBoxUrl = "https://sandbox.itunes.apple.com/verifyReceipt"
con_ProductionUrl = "https://buy.itunes.apple.com/verifyReceipt"
)
var (
NetworkError = errors.New("NetWorkError")
)
// 验证充值是否有效
// bundleIdentifierList配置的BundleIdentifier列表
// productId输入的ProductId
// receiptData订单数据
// isSandBox是否为沙盒模式
// 返回值:
// 充值收据对象
// 是否有效
// 错误对象如果err==NetWorkError,则表明为网络错误)
func ValidateCharge(bundleIdentifierList []string, productId, receiptData string, isSandBox bool) (receiptObj *Receipt, isValid bool, err error) {
// 判断参数是否为空
if len(bundleIdentifierList) == 0 || productId == "" || receiptData == "" {
return
}
// 获取Receipt对象
receiptObj, err = getReceipt(receiptData, isSandBox)
if err != nil {
return
}
if receiptObj.IsBundleIdentifierValid(bundleIdentifierList) == false {
return
}
if receiptObj.IsProductIdValid(productId) == false {
return
}
isValid = true
return
}
func getReceipt(receiptData string, isSandBox bool) (receiptObj *Receipt, err error) {
weburl := con_ProductionUrl
if isSandBox {
weburl = con_SandBoxUrl
}
data := []byte(convertReceiptToPost(receiptData))
statusCode, returnBytes, err := webUtil.PostByteData2(weburl, data, webUtil.GetFormHeader(), nil)
if err != nil {
err = NetworkError
return
}
if statusCode != 200 {
err = fmt.Errorf("StatusCode is wrong:%d", statusCode)
return
}
if len(returnBytes) == 0 {
err = fmt.Errorf("返回的数据为空")
return
}
receiptObj, err = newReceipt(string(returnBytes))
return
}
func convertReceiptToPost(receiptData string) string {
return fmt.Sprintf("{\"receipt-data\":\"%s\"}", receiptData)
}

View File

@@ -0,0 +1,71 @@
package resultStatus
import (
"fmt"
)
type StatusCode int
// ResultStatus
// @description: 状态码数据
type ResultStatus struct {
// 状态码
code StatusCode
// 消息
message string
}
// Code
// @description: 状态码
// parameter:
// @receiver this: this
// return:
// @StatusCode: 状态码
func (this *ResultStatus) Code() StatusCode {
return this.code
}
// Message
// @description: 错误信息
// parameter:
// @receiver this: this
// return:
// @string:
func (this *ResultStatus) Message() string {
return this.message
}
// NewResultStatus
// @description: 创建新的状态码对象
// parameter:
// @_code: 错误码
// @_message: 提示消息
// return:
// @ResultStatus: 状态码对象
func NewResultStatus(_code StatusCode, _message string) ResultStatus {
return ResultStatus{
code: _code,
message: _message,
}
}
// IsSuccess
// @description: 是否是成功
// parameter:
// @receiver this: this
// return:
// @bool: true:成功 false:失败
func (this *ResultStatus) IsSuccess() bool {
return this.code == Success.Code()
}
// String
// @description: 打印状态码信息
// parameter:
// @receiver this: this
// return:
// @string: 状态码信息
func (this *ResultStatus) String() string {
return fmt.Sprintf("Code:%d,Message:%s", this.code, this.message)
}

View File

@@ -0,0 +1,227 @@
package timeUtil
import (
"testing"
"time"
)
// 检查是否在范围内的常规测试
func TestCheckIfInRange(t *testing.T) {
// Check with correct data
timeSpan1 := "13:00:00"
timeSpan2 := "21:00:00"
t1, err := ToDateTime("2017-09-04 15:00:00")
if err != nil {
t.Error(err)
return
}
if CheckIfInRange(t1, timeSpan1, 0, timeSpan2, 0) == false {
t.Fail()
return
}
if CheckIfInRange(t1, timeSpan2, 0, timeSpan1, 0) == false {
t.Fail()
return
}
if CheckIfInRange(t1, timeSpan1, 0, timeSpan2, 5) == false {
t.Fail()
return
}
if CheckIfInRange(t1, timeSpan2, 0, timeSpan1, 5) == false {
t.Fail()
return
}
// Check with incorrect data
t1, err = ToDateTime("2017-09-04 22:00:00")
if err != nil {
t.Error(err)
return
}
if CheckIfInRange(t1, timeSpan1, 0, timeSpan2, 0) {
t.Fail()
return
}
if CheckIfInRange(t1, timeSpan2, 0, timeSpan1, 0) {
t.Fail()
return
}
}
func TestCheckIfInRange2(t *testing.T) {
timeSpan1 := "13:00:00"
timeSpan2 := "21:00:00"
t1, err := ToDateTime("2017-09-04 15:00:00")
if err != nil {
t.Error(err)
return
}
if CheckIfInRange2(t1, timeSpan1, timeSpan2) == false {
t.Fail()
return
}
if CheckIfInRange2(t1, timeSpan2, timeSpan1) == false {
t.Fail()
return
}
if CheckIfInRange2(t1, timeSpan1, timeSpan2) == false {
t.Fail()
return
}
if CheckIfInRange2(t1, timeSpan2, timeSpan1) == false {
t.Fail()
return
}
t1, err = ToDateTime("2017-09-04 22:00:00")
if err != nil {
t.Error(err)
return
}
if CheckIfInRange2(t1, timeSpan1, timeSpan2) {
t.Fail()
return
}
if CheckIfInRange2(t1, timeSpan2, timeSpan1) {
t.Fail()
return
}
}
func TestCheckIfInSameDate(t *testing.T) {
// Check with the same date time
t1, err := ToDateTime("2017-09-04 00:00:00")
if err != nil {
t.Error(err)
return
}
t2, err := ToDateTime("2017-09-04 15:00:00")
if err != nil {
t.Error(err)
return
}
if CheckIfInSameDate(t1, t2) == false {
t.Fail()
return
}
// Check with different date time
t2, err = ToDateTime("2019-12-26 15:00:00")
if err != nil {
t.Error(err)
return
}
if CheckIfInSameDate(t1, t2) {
t.Fail()
return
}
}
func TestAfter(t *testing.T) {
// Check with the same date time
t1, err := ToDateTime("2017-09-04 02:00:00")
if err != nil {
t.Error(err)
return
}
t1 = t1.In(time.UTC)
t2, err := ToDateTime("2017-09-04 01:00:00")
if err != nil {
t.Error(err)
return
}
t2 = t2.In(time.Local)
if After(t2, t1) {
t.Fail()
return
}
if After(t1, t2) == false {
t.Fail()
return
}
}
func TestBefore(t *testing.T) {
// Check with the same date time
t1, err := ToDateTime("2017-09-04 02:00:00")
if err != nil {
t.Error(err)
return
}
t1 = t1.In(time.UTC)
t2, err := ToDateTime("2017-09-04 01:00:00")
if err != nil {
t.Error(err)
return
}
t2 = t2.In(time.Local)
if Before(t2, t1) == false {
t.Fail()
return
}
if Before(t1, t2) {
t.Fail()
return
}
}
func TestEqual(t *testing.T) {
// Check with the same date time
t1, err := ToDateTime("2017-09-04 02:00:00")
if err != nil {
t.Error(err)
return
}
t1 = t1.In(time.UTC)
t2, err := ToDateTime("2017-09-04 01:00:00")
if err != nil {
t.Error(err)
return
}
t2 = t2.In(time.Local)
t3, err := ToDateTime("2017-09-04 01:00:00")
if err != nil {
t.Error(err)
return
}
if Equal(t2, t1) {
t.Fail()
return
}
if Equal(t1, t2) {
t.Fail()
return
}
if Equal(t2, t3) == false {
t.Fail()
return
}
}