摘要:本篇微信开发教程将为大家讲解微信开发编程的知识点,看完这篇文章会让你对微信开发编程的知识点有更加清晰的理解和运用。
本篇微信开发教程将为大家讲解微信开发编程的知识点,看完这篇文章会让你对微信开发编程的知识点有更加清晰的理解和运用。
摘要: 微信公众平台,作为自媒体的旗舰级产品,越来越多的人已经投入它的怀抱。正如它的广告词所说:再小的个体,也有品牌 好吧,闲话不多说,今天要说的是它的IP白名单机制。
我们现在安装的大部分都是电信的家庭宽带,它的公网IP是随机的,当然也可以加钱变成固定IP,也可以通过其他软件映射,都可以...
微信公众平台,作为自媒体的旗舰级产品,越来越多的人已经投入它的怀抱。正如它的广告词所说:再小的个体,也有品牌
好吧,闲话不多说,今天要说的是它的IP白名单机制。
我们现在安装的大部分都是电信的家庭宽带,它的公网IP是随机的,当然也可以加钱变成固定IP,也可以通过其他软件映射,都可以变成固定IP
我说的这个方案,也算其中一种吧,就是通过WebAPI方式,把某一台机器的公网IP固定,然后访问公众号的程序部署在这上面,最后这些程序再通过WebAPI方式被其他客户端调用
好了,还是上代码吧
//3,需先将封面上传至目标公众号 //3.1,下载原公众号中封面图片.判断是否存在?不存在,则下载//注:需判断文件夹是否存在?若不存在,则创建string folderName = CurrentAppInfo.AppPath + @"\MaterialFile\thumb\";if (!Directory.Exists(folderName))
{
Directory.CreateDirectory(folderName);
}string fileFullName = folderName + sourceThumbMediaId + ".png";
FileInfo fi = new FileInfo(fileFullName);if (!fi.Exists)
{
string sourceAccessToken = this.wxpService.GetAccessToken(this.sourceSourceID);
Stream imageStream = this.wxpService.GetMaterial(sourceAccessToken, sourceThumbMediaId);
Image image = Image.FromStream(imageStream);
Bitmap bitmap = new Bitmap(image);
bitmap.Save(fileFullName);
}
//3.2,再上传至目标公众号//此处是上传封面图片string targetAccessToken = this.wxpService.GetAccessToken(this.targetSourceID);
UploadMaterialApiResultModel modelApiResult1 = this.wxpService.UploadMaterialAny(targetAccessToken, new wxpmaterialBillModel()
{
IsTemp = "0",
FileFullName = fi.FullName,
MaterialType = MaterialType.thumb.ToString()
});string targetThumbMediaId = modelApiResult1.media_id;
//3,加工数据
wxpapiaccountBillModel modelSourceApiAccount = this.listApiAccount.FirstOrDefault(c => c.SourceID == this.sourceSourceID);
wxpapiaccountBillModel modelTargetApiAccount = this.listApiAccount.FirstOrDefault(c => c.SourceID == this.targetSourceID);
content = content.Replace(modelSourceApiAccount.SourceCode, modelTargetApiAccount.SourceCode);
content = content.Replace(modelSourceApiAccount.SourceName, modelTargetApiAccount.SourceName);
//二维码图片可能有多个,分隔符是:分号//注:目标地址只获取第1个即可string[] qrcodeUrl1s = modelSourceApiAccount.QRCodeUrlPath.Split(';');string qrcodeUrl2 = modelTargetApiAccount.QRCodeUrlPath.Split(';')[0];foreach (string qrcodeUrl1 in qrcodeUrl1s)
{
content = content.Replace(qrcodeUrl1, qrcodeUrl2);
}
UploadNewsModel modelUpload = new UploadNewsModel()
{
title = title,
author = author,
digest = digest,
content = content,
content_source_url = targetSourceUrl,
show_cover_pic = "0",
thumb_media_id = targetThumbMediaId
};
//4,上传素材至目标公众号
UploadMaterialApiResultModel modelResult = this.wxpService.UploadMaterialNews(targetAccessToken, new List<UploadNewsModel>() { modelUpload });
//4.1,需标记源公众号中此素材已转发
wxpmaterialBillModel modelEditToSource = new wxpmaterialBillModel()
{
SourceID = this.sourceSourceID,
MaterialCode = this.sourceMaterialCode,
IsTranspond = "1",
ActionName = "SetIsTranspond",
};this.wxpService.UpdateMaterial(new List<wxpmaterialBillModel>() { modelEditToSource });
如上图所示,这是实现图文素材从公众号A复制至公众号B里的代码,这种情况下,我每天在家里打开电脑时,都要在IP白名单中重新设置下电脑的公网IP,不然,会提示
改成下面的代码就可以轻松解决,我把程序部署到阿里云上,so easy,换个思路,又是一片新的天空。
copymaterialQueryModel copymaterialParamModel = new Base.Models.copymaterialQueryModel()
{
sourceSourceID = this.sourceSourceID,
sourceMaterialCode = this.sourceMaterialCode,
targetSourceID = this.targetSourceID,
title = title,
digest = digest,
author = author,
targetSourceUrl = targetSourceUrl,
wxAccessToken = wxAccessToken
};
UploadMaterialApiResultModel modelResult = WebAPIHelper.WebAPIPostData<UploadMaterialApiResultModel>(ControllerName.WXPublicApi, WXPublicApiActionName.CopyMaterial.ToString(), copymaterialParamModel);
最后,发布一个彩蛋,做自媒体的可以看看
Navi.Soft31.微信WinForm框架(含下载地址)
Navi.Soft31.产品.登录器(永久免费)
希望这篇微信开发文章可以帮助到你。总之,同学们,你想要的职坐标微信开发频道都能找到!
您输入的评论内容中包含违禁敏感词
我知道了
请输入正确的手机号码
请输入正确的验证码
您今天的短信下发次数太多了,明天再试试吧!
我们会在第一时间安排职业规划师联系您!
您也可以联系我们的职业规划师咨询:
版权所有 职坐标-一站式IT培训就业服务领导者 沪ICP备13042190号-4
上海海同信息科技有限公司 Copyright ©2015 www.zhizuobiao.com,All Rights Reserved.
沪公网安备 31011502005948号