微信mvc上传图片到服务器,.net mvc 使用盛派Senparc.Weixin 上传图片接口

wx.config({//debug: true,

appId: '@ViewBag.AppId',

timestamp:'@ViewBag.Timestamp',

nonceStr:'@ViewBag.NonceStr',

signature:'@ViewBag.Signature',

jsApiList: ['chooseImage','previewImage','uploadImage','downloadImage']

});

wx.ready(function () {//5 图片接口//5.1 拍照、本地选图

var images ={

localId: [],

serverId: []

};

document.querySelector('#btnAddImage').onclick =function () {

wx.chooseImage({

count:3, //默认9,设置可以同时上传的图片数量

sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有

sourceType: ['album', 'camera'], //可以指定来源是相册还是相机,默认二者都有

success: function (res) {

images.localId=res.localIds;//alert('已选择 ' + res.localIds.length + ' 张图片');

var i = 0, length =images.localId.length;

images.serverId=[];

function upload() {

wx.uploadImage({

localId: images.localId[i],

success: function (res) {

i++;//alert('已上传:' + i + '/' + length);

images.serverId.push(res.serverId);//TODO: res.serverId 就是 media_id,根据它去微信服务器读取图片数据:自定义上传到自己服务器

var imageJson = $("#hdImageJson").val();

$.ajax({

type:'post',

url:'/Common/AddImage',async: false,

data: {

media_id: res.serverId,

imageJson: imageJson,

folderName:"MutualHelp"},

success: function (data) {if (data.ImageUrl != '') {//返回 图片在我们自己的服务器的url

var img = "%22%20+%20data.ImageUrl%20+%20%22";

$("#imgList").append(img);

$("#hdImageJson").val(data.ImageJson);

}

},

error: function (err) {

}

})if (i

upload();

}

},

fail: function (res) {

alert(JSON.stringify(res));

}

});

}

upload();

}

});

};

});

您好!要使用Senparc.Weixin.AspNet微信分享接口,需要按照以下步骤进行操作: 1. 安装Senparc.Weixin.AspNet 使用NuGet安装Senparc.Weixin.AspNet,可以在Visual Studio的NuGet包管理器中搜索并安装。 2. 配置微信公众号信息 在Web.config文件中配置微信公众号的AppId、AppSecret等信息,以便进行微信授权和分享。例如: ```xml <appSettings> <add key="WeixinAppId" value="your_appid" /> <add key="WeixinAppSecret" value="your_appsecret" /> <add key="WeixinToken" value="your_token" /> <add key="WeixinEncodingAESKey" value="your_encodingAESKey" /> </appSettings> ``` 3. 创建分享接口 创建一个Controller,并添加一个Action来处理分享请求,例如: ```csharp public class WeixinShareController : Controller { [HttpPost] public ActionResult Share(string url) { var jssdkUiPackage = JSSDKHelper.GetJsSdkUiPackage(WeixinConfig.WeixinAppId, WeixinConfig.WeixinAppSecret, url); return Json(jssdkUiPackage); } } ``` 在Action中,调用Senparc.Weixin.MP.Helpers.JSSDKHelper.GetJsSdkUiPackage方法获取JSSDK的UiPackage信息,并返回Json格式的结果。 4. 在前端页面中调用分享接口 在前端页面中,通过Ajax调用分享接口获取分享信息,例如: ```javascript $.post('/WeixinShare/Share', { url: location.href }, function (result) { wx.config({ debug: false, appId: result.appId, timestamp: result.timestamp, nonceStr: result.nonceStr, signature: result.signature, jsApiList: ['onMenuShareTimeline', 'onMenuShareAppMessage'] }); wx.ready(function () { wx.onMenuShareTimeline({ title: '分享标题', link: location.href, imgUrl: '分享图片地址' }); wx.onMenuShareAppMessage({ title: '分享标题', desc: '分享描述', link: location.href, imgUrl: '分享图片地址' }); }); }); ``` 在页面加载完成后,通过Ajax调用分享接口获取分享信息,然后使用wx.config和wx.ready方法进行微信JSSDK的初始化和分享设置。 以上是使用Senparc.Weixin.AspNet微信分享接口的基本流程,希望能对您有所帮助。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值