1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- using QWPlatform.SystemLibrary.LogManager;
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Net;
- using System.Text;
- using System.Threading.Tasks;
- namespace PMS.BusinessModels.ModelExtend
- {
- public class HttpCrossDomain
- {
- /// <summary>
- /// 跨域访问
- /// </summary>
- /// <param name="url"></param>
- /// <param name="param"></param>
- /// <returns></returns>
- public static string Post(string url, string param, int time = 60000)
- {
- try
- {
- var address = new Uri(url);
- var request = WebRequest.Create(address) as HttpWebRequest;
- request.Method = "POST";
- request.ContentType = "application/json;charset=utf-8"; //"application/x-www-form-urlencoded";
- request.Timeout = time;
- var byteData = Encoding.UTF8.GetBytes(param == null ? "" : param);
- request.ContentLength = byteData.Length;
- using (var postStream = request.GetRequestStream())
- {
- postStream.Write(byteData, 0, byteData.Length);
- }
- var result = "";
- using (var response = request.GetResponse() as HttpWebResponse)
- {
- var reader = new StreamReader(response.GetResponseStream());
- result = reader.ReadToEnd();
- }
- return result;
- } catch (Exception ex)
- {
- Logger.Instance.Error("调用Post失败,原因:" + ex);
- return "";
- }
- }
- /// <summary>
- /// 跨域访问
- /// </summary>
- /// <param name="url"></param>
- /// <param name="param"></param>
- /// <returns></returns>
- public static string Get(string url, int time = 60000)
- {
- var address = new Uri(url);
- var request = WebRequest.Create(address) as HttpWebRequest;
- request.Method = "GET";
- request.ContentType = "application/json;charset=utf-8"; //"application/x-www-form-urlencoded";
- request.Timeout = time;
- var result = "";
- try
- {
- using (var response = request.GetResponse() as HttpWebResponse)
- {
- var reader = new StreamReader(response.GetResponseStream());
- result = reader.ReadToEnd();
- }
- }
- catch (Exception ex)
- {
- Logger.Instance.Error("调用Get失败,原因:" + ex);
- result = "";
- }
- return result;
- }
- }
- public class WechatToken{
- public string access_token { get; set; }
- public string openid { get; set; }
- public string scope { get; set; }
- public string expires_in { get; set; }
- }
- public class WechatUserinfo {
- public string nickname { get; set; }
- public string sex { get; set; }
- public string province { get; set; }
- public string city { get; set; }
- public string country { get; set; }
- //public string headimgurl { get; set; }
- //public string privilege { get; set; }
- public string unionid { get; set; }
- }
- }
|