You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
67 lines
2.2 KiB
C#
67 lines
2.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Web;
|
|
using System.Data;
|
|
using System.Text;
|
|
using System.Configuration;
|
|
using DSWeb.Areas.Mobile.Models.Login;
|
|
using MyShippingWeb.Classes;
|
|
using DSWeb.TruckMng.Helper;
|
|
|
|
namespace DSWeb.Areas.Mobile.DAL
|
|
{
|
|
public class AccessTokenDAL
|
|
{
|
|
//获取AccessToken
|
|
public static string GetAccessToken(){
|
|
string sql = "select top 1 AccessToken from sys_WeChatConfig order by updatetime desc";
|
|
|
|
DBLog.Log("GetAccessToken","sql",sql);
|
|
var token = SQLHelperDS.ExcuteScalarSQL(sql) ;
|
|
if (token==null||token==DBNull.Value || token.ToString()=="")
|
|
{
|
|
DBLog.Log("RefrashAccessToken","before");
|
|
token = RefrashAccessToken();
|
|
DBLog.Log("RefrashAccessToken", "end", token.ToString());
|
|
}
|
|
DBLog.Log("GetAccessToken","end");
|
|
return token.ToString();
|
|
}
|
|
|
|
//设置AccessToken
|
|
public static bool SetAccessToken (string token)
|
|
{
|
|
string sqlins = "insert into sys_WeChatConfig (accesstoken) values('" + token + "')";
|
|
|
|
int rst = SQLHelperDS.ExcuteSQL(sqlins);
|
|
return rst>0;
|
|
}
|
|
|
|
//刷新AccessToken
|
|
public static string RefrashAccessToken ( ) {
|
|
string appid = ConfigurationManager.AppSettings["appid"].ToString();
|
|
string secret = ConfigurationManager.AppSettings["secret"].ToString();
|
|
string url = string.Format(@"https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={0}&secret={1}",appid,secret);
|
|
string respStr = HttpHelper.HttpGet(url);
|
|
DBLog.Log("RefrashAccessToken", "respStr", respStr);
|
|
AccessTokenModel token = JsonConvert.Deserialize<AccessTokenModel>(respStr);
|
|
|
|
DBLog.Log("RefrashAccessToken","token",token.access_token);
|
|
string sqlins = "insert into sys_WeChatConfig (accesstoken) values('"+token.access_token+"')";
|
|
|
|
int rst = SQLHelperDS.ExcuteSQL(sqlins);
|
|
|
|
if (rst>0)
|
|
{
|
|
return token.access_token;
|
|
}
|
|
else
|
|
{
|
|
return "";
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
} |