Commit a7d1e2cb authored by liudong1993's avatar liudong1993

获取二维码

parent bcfc4ca8
...@@ -291,6 +291,35 @@ namespace Mall.Common.Plugin ...@@ -291,6 +291,35 @@ namespace Mall.Common.Plugin
} }
} }
/// <summary>
/// 执行HTTP POST请求。
/// </summary>
/// <param name="url">请求地址</param>
/// <param name="postDataStr">请求地址</param>
/// <returns>HTTP响应</returns>
public static string HttpPostForGetWXQRCodePath(string url, string postDataStr,string path)
{
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
req.Method = "POST";
req.ContentType = "application/octet-stream";
req.ContentLength = Encoding.UTF8.GetByteCount(postDataStr);
Stream myRequestStream = req.GetRequestStream();
StreamWriter myStreamWriter = new StreamWriter(myRequestStream, Encoding.GetEncoding("gb2312"));
myStreamWriter.Write(postDataStr);
myStreamWriter.Close();
HttpWebResponse rsp = (HttpWebResponse)req.GetResponse();
if (string.IsNullOrWhiteSpace(rsp.CharacterSet))
{
return GetResponseAsStringBase64_V2(rsp, Encoding.UTF8, path);
}
else
{
Encoding encoding = Encoding.GetEncoding(rsp.CharacterSet);
return GetResponseAsStringBase64_V2(rsp, encoding, path);
}
}
/// <summary> /// <summary>
/// 把响应流转换为文本 /// 把响应流转换为文本
...@@ -319,6 +348,46 @@ namespace Mall.Common.Plugin ...@@ -319,6 +348,46 @@ namespace Mall.Common.Plugin
} }
} }
/// <summary>
/// 把响应流转换为文本
/// </summary>
/// <param name="rsp"></param>
/// <param name="encoding"></param>
/// <returns></returns>
private static string GetResponseAsStringBase64_V2(HttpWebResponse rsp, Encoding encoding, string path)
{
System.IO.Stream stream = null;
try
{
// 以字符流的方式读取HTTP响应
stream = rsp.GetResponseStream();
return ReadImageForStream_V2(stream, path);
}
catch
{
return "";
}
finally
{
// 释放资源
if (stream != null) stream.Close();
if (rsp != null) rsp.Close();
}
}
/// <summary>
/// 获取
/// </summary>
/// <param name="imgstream"></param>
/// <returns></returns>
public static string ReadImageForStream_V2(Stream imgstream,string path)
{
System.Drawing.Image result = System.Drawing.Image.FromStream(imgstream);
System.Drawing.Bitmap bit = new System.Drawing.Bitmap(result);
bit.Save(path, System.Drawing.Imaging.ImageFormat.Jpeg);
return path;
}
/// <summary> /// <summary>
/// 获取 /// 获取
/// </summary> /// </summary>
......
...@@ -4673,6 +4673,7 @@ namespace Mall.Module.Product ...@@ -4673,6 +4673,7 @@ namespace Mall.Module.Product
if (demodel.GoodsId > 0) if (demodel.GoodsId > 0)
{ {
goodsRepository.SetGoodsNewId(demodel.GoodsId ?? 0, Id, trans); goodsRepository.SetGoodsNewId(demodel.GoodsId ?? 0, Id, trans);
Id = demodel.GoodsId ?? 0;
} }
//插入分类 //插入分类
foreach (var item in demodel.CategoryList) foreach (var item in demodel.CategoryList)
......
...@@ -3954,14 +3954,18 @@ namespace Mall.Module.User ...@@ -3954,14 +3954,18 @@ namespace Mall.Module.User
System.Threading.Tasks.Task.Run(() => CacheManager.AppletWeChat.WeiXinReidsCache.Set(appletWeChatModel.MiniAppId, token)); System.Threading.Tasks.Task.Run(() => CacheManager.AppletWeChat.WeiXinReidsCache.Set(appletWeChatModel.MiniAppId, token));
} }
if (!string.IsNullOrEmpty(token)) { if (!string.IsNullOrEmpty(token)) {
string GetImageUrl = "https://api.weixin.qq.com/cgi-bin/wxaapp/createwxaqrcode?access_token=" + token; //string GetImageUrl = "https://api.weixin.qq.com/cgi-bin/wxaapp/createwxaqrcode?access_token=" + token;//获取二维码
string GetImageUrl = "https://api.weixin.qq.com/wxa/getwxacode?access_token="+ token;//获取小程序码
var postData = new var postData = new
{ {
path, path,
width width
}; };
var Robj = HttpHelper.HttpPostForWXQRCode(GetImageUrl, JsonHelper.Serialize(postData)); string pathName = Guid.NewGuid().ToString() + ".jpg";
var Robj1 = HttpHelper.HttpPost(GetImageUrl, JsonHelper.Serialize(postData), ""); string basepath = AppContext.BaseDirectory;
string path_server = basepath + "\\upfile\\temporary\\" + pathName;
var Robj = HttpHelper.HttpPostForGetWXQRCodePath(GetImageUrl, JsonHelper.Serialize(postData), path_server);
//var Robj1 = HttpHelper.HttpPost(GetImageUrl, JsonHelper.Serialize(postData), "");
return Robj; return Robj;
} }
return ""; return "";
......
...@@ -959,6 +959,30 @@ namespace Mall.WebApi.Controllers.User ...@@ -959,6 +959,30 @@ namespace Mall.WebApi.Controllers.User
} }
#endregion #endregion
#region 获取小程序码
/// <summary>
/// 获取微信小程序码
/// </summary>
/// <returns></returns>
[HttpPost]
public ApiResult GetWeiXinQRCodeForApplet()
{
var req = RequestParm;
var userInfo = AppletUserInfo;
JObject parms = JObject.Parse(req.msg.ToString());
string Path = parms.GetStringValue("Path");//路径
int With = parms.GetInt("With", 430);//大小
if (string.IsNullOrEmpty(Path))
{
return ApiResult.ParamIsNull("请传递路径");
}
string base64Img = userModule.GetWeiXinQRCode(Path, With, userInfo.MallBaseId);
return ApiResult.Success("", base64Img);
}
#endregion
#region 个人中心余额/积分/优惠券气泡 #region 个人中心余额/积分/优惠券气泡
/// <summary> /// <summary>
......
...@@ -2539,7 +2539,7 @@ namespace Mall.WebApi.Controllers.User ...@@ -2539,7 +2539,7 @@ namespace Mall.WebApi.Controllers.User
var req = RequestParm; var req = RequestParm;
JObject parms = JObject.Parse(req.msg.ToString()); JObject parms = JObject.Parse(req.msg.ToString());
string Path = parms.GetStringValue("Path");//路径 string Path = parms.GetStringValue("Path");//路径
int With = parms.GetInt("With", 100);//大小 int With = parms.GetInt("With", 430);//大小
if (string.IsNullOrEmpty(Path)) { if (string.IsNullOrEmpty(Path)) {
return ApiResult.ParamIsNull("请传递路径"); return ApiResult.ParamIsNull("请传递路径");
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment