获取OpenId和SessionKey

private string GetOpenIdAndSessionKeyString(string code)
      {
         string wxUrl = "https://api.weixin.qq.com/sns/jscode2session?appid=" + CommonData.WxAppId + "&secret=" + CommonData.WxAppSecret + "&js_code=" + code + "&grant_type=authorization_code";
         return GetResponse(wxUrl);
      }

code

public static string AESDecrypt(string text)
{
    try
    {

        //判断是否是16位 如果不够补0
        //text = tests(text);
        //16进制数据转换成byte
        byte[] encryptedData =Convert.FromBase64String(text);  // strToToHexByte(text);
        RijndaelManaged rijndaelCipher = new RijndaelManaged();
        rijndaelCipher.Key =Convert.FromBase64String(AesKey); // Encoding.UTF8.GetBytes(AesKey);
        rijndaelCipher.IV = Convert.FromBase64String(AesIV);// Encoding.UTF8.GetBytes(AesIV);
        rijndaelCipher.Mode = CipherMode.CBC;
        rijndaelCipher.Padding = PaddingMode.PKCS7;
        ICryptoTransform transform = rijndaelCipher.CreateDecryptor();
        byte[] plainText = transform.TransformFinalBlock(encryptedData, 0, encryptedData.Length);
        string result = Encoding.UTF8.GetString(plainText);//UTF8防止乱码
        //int index = result.LastIndexOf('>');
        //result = result.Remove(index + 1);
        return result;
    }
    catch (Exception ex)
    {
        return null;

    }
}

 

posted on 2018-08-15 15:28  邢帅杰  阅读(177)  评论(0编辑  收藏  举报