|
|
|
|
@ -28,6 +28,14 @@ namespace _24Hour
|
|
|
|
|
/// </summary> |
|
|
|
|
private string secret = "wx48108a0c98a3dab0"; |
|
|
|
|
/// <summary> |
|
|
|
|
/// 微信公众号AppID |
|
|
|
|
/// </summary> |
|
|
|
|
private string Gzhappid = "wx48108a0c98a3dab0"; |
|
|
|
|
/// <summary> |
|
|
|
|
/// 微信公众号密码 |
|
|
|
|
/// </summary> |
|
|
|
|
private string Gzhsecret = "wx48108a0c98a3dab0"; |
|
|
|
|
/// <summary> |
|
|
|
|
/// 小程序secretID |
|
|
|
|
/// </summary> |
|
|
|
|
private string secid = "e752e4fba67526eca21313a18c96a58f"; |
|
|
|
|
@ -43,7 +51,10 @@ namespace _24Hour
|
|
|
|
|
appid = $"{configuration.GetSection("Wechat:appid").Value}"; |
|
|
|
|
secret = $"{configuration.GetSection("Wechat:secret").Value}"; |
|
|
|
|
secid = $"{configuration.GetSection("Wechat:secid").Value}"; |
|
|
|
|
Gzhappid = $"{configuration.GetSection("WechatGzh:appid").Value}"; |
|
|
|
|
Gzhsecret = $"{configuration.GetSection("WechatGzh:secret").Value}"; |
|
|
|
|
} |
|
|
|
|
//小程序获取openId |
|
|
|
|
public async Task<Result> GetOpenId(string code) |
|
|
|
|
{ |
|
|
|
|
var ret = new Result(); |
|
|
|
|
@ -69,6 +80,36 @@ namespace _24Hour
|
|
|
|
|
} |
|
|
|
|
return ret; |
|
|
|
|
} |
|
|
|
|
/// <summary> |
|
|
|
|
/// 微信公众号获取openId |
|
|
|
|
/// </summary> |
|
|
|
|
/// <param name="code"></param> |
|
|
|
|
/// <returns></returns> |
|
|
|
|
public async Task<Result> GetGzhOpenId(string code) |
|
|
|
|
{ |
|
|
|
|
var ret = new Result(); |
|
|
|
|
var reponse = HttpHelper.Get($" https://api.weixin.qq.com/sns/oauth2/access_token?appid={Gzhappid}&secret={Gzhsecret}&code={code}&grant_type=authorization_code"); |
|
|
|
|
var opendata = reponse; |
|
|
|
|
var data = JsonConvert.DeserializeAnonymousType(opendata, new |
|
|
|
|
{ |
|
|
|
|
openid = default(string), |
|
|
|
|
session_key = default(string), |
|
|
|
|
unionid = default(string), |
|
|
|
|
errcode = default(int), |
|
|
|
|
errmsg = default(string), |
|
|
|
|
}); |
|
|
|
|
if (data.errcode == 0) |
|
|
|
|
{ |
|
|
|
|
ret.IsSucceed = true; |
|
|
|
|
ret.result = data.openid; |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
ret.IsSucceed = false; |
|
|
|
|
ret.Message = data.errmsg; |
|
|
|
|
} |
|
|
|
|
return ret; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
/// 律师预约微信消息提醒,成功 |
|
|
|
|
@ -156,7 +197,7 @@ namespace _24Hour
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(token)) |
|
|
|
|
{ |
|
|
|
|
string geturl = $"https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wx48108a0c98a3dab0&secret=e752e4fba67526eca21313a18c96a58f"; |
|
|
|
|
string geturl = $"https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={appid}&secret={secret}"; |
|
|
|
|
var re1 = HttpHelper.Get(geturl); |
|
|
|
|
if (re1.Jsonstr("errcode") == null) |
|
|
|
|
{ |
|
|
|
|
@ -211,5 +252,79 @@ namespace _24Hour
|
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
/// 微信公众号消息提醒,推送检察官 |
|
|
|
|
/// </summary> |
|
|
|
|
/// <returns></returns> |
|
|
|
|
public bool gzhwxts(string? useropenId, string? name,string? phone, string? matter, string? attention) |
|
|
|
|
{ |
|
|
|
|
try |
|
|
|
|
{ |
|
|
|
|
var token = ""; |
|
|
|
|
|
|
|
|
|
// 获取缓存 |
|
|
|
|
token = cache.Get("gzhtoken")?.ToString(); |
|
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(token)) |
|
|
|
|
{ |
|
|
|
|
string geturl = $"https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={Gzhappid}&secret={Gzhsecret}"; |
|
|
|
|
var re1 = HttpHelper.Get(geturl); |
|
|
|
|
if (re1.Jsonstr("errcode") == null) |
|
|
|
|
{ |
|
|
|
|
token = re1.Jsonstr("access_token"); |
|
|
|
|
|
|
|
|
|
// 移除缓存 |
|
|
|
|
cache.Remove("gzhtoken"); |
|
|
|
|
// 添加缓存 |
|
|
|
|
cache.Add("gzhtoken", token, new CacheItemPolicy { AbsoluteExpiration = DateTime.Now.AddMinutes(120) }); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
string url = $"https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=";//发送地址 |
|
|
|
|
try |
|
|
|
|
{ |
|
|
|
|
object msg = null; |
|
|
|
|
string posturl = $"{url}{token}";//发送地址 |
|
|
|
|
var thing4 = matter; |
|
|
|
|
var thing5 = attention; |
|
|
|
|
if (!string.IsNullOrEmpty(matter) && matter.Length > 20) |
|
|
|
|
thing4 = matter.Substring(0, 17) + "..."; |
|
|
|
|
if (!string.IsNullOrEmpty(attention) && attention.Length > 20) |
|
|
|
|
thing5 = attention.Substring(0, 17) + "..."; |
|
|
|
|
msg = new |
|
|
|
|
{ |
|
|
|
|
touser = useropenId, |
|
|
|
|
template_id = "SmCAFFqHSnGC4FnRBFgkmuBvTBWkPnWi4zkjshrpz_8", |
|
|
|
|
//miniprogram =new{ |
|
|
|
|
// appid= appid, |
|
|
|
|
// pagepath= "pages/selfService/reception/reception" |
|
|
|
|
//}, |
|
|
|
|
//miniprogram_state = $"{_configuration.GetSection("Wechat:miniprogram_state").Value}", |
|
|
|
|
//lang = "zh_CN", |
|
|
|
|
data = new |
|
|
|
|
{ |
|
|
|
|
//name1 = new { value = $"{name}"},// |
|
|
|
|
thing1 = new { value = $"{name}" },// |
|
|
|
|
phone_number4 = new { value = $"{phone}" },// |
|
|
|
|
thing5 = new { value = $"{thing4}" },// |
|
|
|
|
}, |
|
|
|
|
}; |
|
|
|
|
var re = HttpHelper.Post(posturl, msg); |
|
|
|
|
if (re.Jsonstr("errcode") == "0") |
|
|
|
|
return true; |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
catch (Exception ex) |
|
|
|
|
{ |
|
|
|
|
} |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
catch (Exception ex) |
|
|
|
|
{ |
|
|
|
|
} |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|