hotime/example/app/init.go
2022-02-24 06:26:36 +08:00

160 lines
6.8 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package app
import (
. "../../../hotime"
. "../../../hotime/common"
"../../dri/aliyun"
"../../dri/tencent"
"fmt"
"github.com/silenceper/wechat"
"github.com/silenceper/wechat/cache"
"gopkg.in/chanxuehong/wechat.v2/mch/core"
"gopkg.in/chanxuehong/wechat.v2/mch/pay"
"io/ioutil"
"os"
"path/filepath"
"time"
)
// Project 管理端项目
var Project = Proj{
//"user": UserCtr,
"tag": tagCtr,
"analyse": analyseCtr,
"user": User,
"wechat": Wechat,
"question": Question,
}
var weixin *wechat.Wechat //微信登录实例
//var appIns = Application{}
var wxpayClient *core.Client
//生成随机码的4位随机数
func getCode() string {
//res := ""
//for i := 0; i < 4; i++ {
res := ObjToStr(RandX(1000, 9999))
//}
return res
}
func getCompany(name, path string) Map {
os.Setenv("ZONEINFO", "config/data.zip")
res := tencent.GetCompany("AKIDklZa1qBr3B0x1G643cg8B6UO5JZm2KX8o43G", "tdda7oro526h96dvicYkep1xsWFmHkt33xvqs2K", name)
c := Map{}
base := Map{}
if res.GetInt("code") != 200 {
return base
}
if res.GetInt("code") == 200 {
c = res.GetMap("data").GetMap("data")
base = c.GetMap("base")
base["allows"] = len(c.GetSlice("allows"))
base["branches"] = len(c.GetSlice("branches"))
base["changes"] = len(c.GetSlice("changes"))
base["employees"] = len(c.GetSlice("employees"))
base["exceptions"] = len(c.GetSlice("exceptions"))
base["mPledges"] = len(c.GetSlice("mPledges"))
base["originalName"] = len(c.GetSlice("originalName"))
base["partners"] = len(c.GetSlice("partners"))
base["pledges"] = len(c.GetSlice("pledges"))
base["punishes"] = len(c.GetSlice("punishes"))
base["shiXinItems"] = len(c.GetSlice("shiXinItems"))
base["spotChecks"] = len(c.GetSlice("spotChecks"))
base["taxCreditltems"] = len(c.GetSlice("taxCreditltems"))
base["zhiXingItems"] = len(c.GetSlice("zhiXingItems"))
base["contactInfo"] = c["contactInfo"]
base["industry"] = c["industry"]
base["liquidation"] = c["liquidation"]
}
aliyun.DefaultCompany.Init("06c6a07e89dd45c88de040ee1489eef7")
data := aliyun.DefaultCompany.GetCompanyOtherAll(name)
base["OtherCopyrightsInfo"] = data.GetMap("OtherCopyrightsInfo").GetInt("total")
base["PatentsInfo"] = data.GetMap("PatentsInfo").GetInt("total")
base["ProfileTags"] = data.GetSlice("ProfileTags")
base["SoftwareCopyrightsInfo"] = data.GetMap("SoftwareCopyrightsInfo").GetInt("total")
base["TrademarksInfo"] = data.GetMap("TrademarksInfo").GetInt("total")
if res.GetInt("code") == 200 {
data["base"] = c
}
_ = os.MkdirAll(filepath.Dir(path), os.ModeDir)
ioutil.WriteFile(path, []byte(data.ToJsonString()), os.ModePerm)
return base
}
//微信获取个人信息
func Weixin(this *Context) *wechat.Wechat {
if weixin == nil {
cache1 := cache.Cache(WechatCache{this.CacheIns})
config := wechat.Config{Cache: cache1, AppID: this.Config.GetString("wechatAppid"), AppSecret: this.Config.GetString("wechatAppscript")}
weixin = wechat.NewWechat(&config)
}
return weixin
}
//微信获取个人信息
func WxPayClient(this *Context, sn string, money int64, openid string) Map {
if wxpayClient == nil {
wxpayClient = core.NewClient(this.Config.GetString("wechatAppid"), this.Config.GetString("wechatChid"), this.Config.GetString("wechatChkey"), nil)
}
res, err := pay.UnifiedOrder2(wxpayClient, &pay.UnifiedOrderRequest{
// 必选参数
Body: "微信充值", // 商品或支付单简要描述
OutTradeNo: sn, // 商户系统内部的订单号,32个字符内、可包含字母, 其他说明见商户订单号
TotalFee: money, // ObjToInt64(umoney*100), // `xml:"total_fee"` // 订单总金额,单位为分,详见支付金额
//SpbillCreateIP string `xml:"spbill_create_ip"` // APP和网页支付提交用户端ipNative支付填调用微信支付API的机器IP。
NotifyURL: this.Config.GetString("wechatPayCallBack"), // string `xml:"notify_url"` // 接收微信支付异步通知回调地址通知url必须为直接可访问的url不能携带参数。
TradeType: "JSAPI", // string `xml:"trade_type"` // 取值如下JSAPINATIVEAPP详细说明见参数规定
// 可选参数
DeviceInfo: "WEB", // string `xml:"device_info"` // 终端设备号(门店号或收银设备ID)注意PC网页或公众号内支付请传"WEB"
// NonceStr string `xml:"nonce_str"` // 随机字符串不长于32位。NOTE: 如果为空则系统会自动生成一个随机字符串。
//SignType string `xml:"sign_type"` // 签名类型默认为MD5支持HMAC-SHA256和MD5。
// Detail:"充值",// string `xml:"detail"` // 商品名称明细列表
//Attach string `xml:"attach"` // 附加数据在查询API和支付通知中原样返回该字段主要用于商户携带订单的自定义数据
//FeeType string `xml:"fee_type"` // 符合ISO 4217标准的三位字母代码默认人民币CNY其他值列表详见货币类型
//TimeStart time.Time `xml:"time_start"` // 订单生成时间格式为yyyyMMddHHmmss如2009年12月25日9点10分10秒表示为20091225091010。其他详见时间规则
//TimeExpire time.Time `xml:"time_expire"` // 订单失效时间格式为yyyyMMddHHmmss如2009年12月27日9点10分10秒表示为20091227091010。其他详见时间规则
//GoodsTag string `xml:"goods_tag"` // 商品标记,代金券或立减优惠功能的参数,说明详见代金券或立减优惠
// ProductId :"CHONGZHI",// string `xml:"product_id"` // trade_type=NATIVE此参数必传。此id为二维码中包含的商品ID商户自行定义。
// LimitPay string `xml:"limit_pay"` // no_credit--指定不能使用信用卡支付
OpenId: openid, //user.GetString("wuid"), // string `xml:"openid"` // rade_type=JSAPI此参数必传用户在商户appid下的唯一标识。
// SubOpenId string `xml:"sub_openid"` // trade_type=JSAPI此参数必传用户在子商户appid下的唯一标识。openid和sub_openid可以选传其中之一如果选择传sub_openid,则必须传sub_appid。
// SceneInfo string `xml:"scene_info"` // 该字段用于上报支付的场景信息,针对H5支付有以下三种场景,请根据对应场景上报,H5支付不建议在APP端
})
if err != nil {
fmt.Println(err)
return nil
}
wcpay := Map{
"appId": this.Config.Get("wechatAppid"),
"timeStamp": ObjToStr(time.Now().Unix()),
"nonceStr": getSn(),
"package": "prepay_id=" + res.PrepayId,
"signType": "MD5",
}
wcpay["paySign"] = core.JsapiSign(this.Config.GetString("wechatAppid"), wcpay.GetString("timeStamp"), wcpay.GetString("nonceStr"), wcpay.GetString("package"), "MD5", this.Config.GetString("wechatChkey"))
return wcpay
}
//生成随机码的6位md5
func getSn() string {
x := Rand(8)
return Substr(Md5(ObjToStr(int64(x)+time.Now().UnixNano()+int64(Rand(6)))), 0, 6)
}