2022-10-30 15:44:05 +00:00
|
|
|
|
package app
|
|
|
|
|
|
|
|
|
|
import (
|
2022-10-30 17:18:19 +00:00
|
|
|
|
. "code.hoteas.com/golang/hotime"
|
|
|
|
|
. "code.hoteas.com/golang/hotime/common"
|
|
|
|
|
"code.hoteas.com/golang/hotime/dri/aliyun"
|
|
|
|
|
"code.hoteas.com/golang/hotime/dri/tencent"
|
2022-10-30 15:44:05 +00:00
|
|
|
|
"fmt"
|
|
|
|
|
"github.com/silenceper/wechat"
|
2023-03-02 18:46:29 +00:00
|
|
|
|
"github.com/silenceper/wechat/cache"
|
2022-10-30 15:44:05 +00:00
|
|
|
|
"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,
|
|
|
|
|
"category": Category,
|
|
|
|
|
"sms": Sms,
|
|
|
|
|
}
|
|
|
|
|
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")
|
2022-10-30 17:18:19 +00:00
|
|
|
|
|
|
|
|
|
res := tencent.Company.GetCompany(name)
|
2022-10-30 15:44:05 +00:00
|
|
|
|
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"]
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-30 17:18:19 +00:00
|
|
|
|
data := aliyun.Company.GetCompanyOtherAll(name)
|
2022-10-30 15:44:05 +00:00
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//微信获取个人信息
|
2023-03-02 18:46:29 +00:00
|
|
|
|
func Weixin(this *Context) *wechat.Wechat {
|
|
|
|
|
if weixin == nil {
|
|
|
|
|
cache1 := cache.NewMemory()
|
|
|
|
|
config := wechat.Config{Cache: cache1, AppID: this.Config.GetString("wechatAppID"), AppSecret: this.Config.GetString("wechatAppSecret")}
|
|
|
|
|
weixin = wechat.NewWechat(&config)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return weixin
|
|
|
|
|
}
|
2022-10-30 15:44:05 +00:00
|
|
|
|
|
|
|
|
|
//微信获取个人信息
|
|
|
|
|
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和网页支付提交用户端ip,Native支付填调用微信支付API的机器IP。
|
|
|
|
|
NotifyURL: this.Config.GetString("wechatPayCallBack"), // string `xml:"notify_url"` // 接收微信支付异步通知回调地址,通知url必须为直接可访问的url,不能携带参数。
|
|
|
|
|
TradeType: "JSAPI", // string `xml:"trade_type"` // 取值如下:JSAPI,NATIVE,APP,详细说明见参数规定
|
|
|
|
|
|
|
|
|
|
// 可选参数
|
|
|
|
|
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)
|
|
|
|
|
}
|