微信小程序> 解决微信公众平台IP白名单

解决微信公众平台IP白名单

浏览量:480 时间: 来源:xiyang1011

微信公众平台,作为自媒体的旗舰级产品,越来越多的人已经投入它的怀抱。正如它的广告词所说:再小的个体,也有品牌

好吧,闲话不多说,今天要说的是它的IP白名单机制。

小程序

小程序

 

我们现在安装的大部分都是电信的家庭宽带,它的公网IP是随机的,当然也可以加钱变成固定IP,也可以通过其他软件映射,都可以变成固定IP

我说的这个方案,也算其中一种吧,就是通过WebAPI方式,把某一台机器的公网IP固定,然后访问公众号的程序部署在这上面,最后这些程序再通过WebAPI方式被其他客户端调用

好了,还是上代码吧

//3,需先将封面上传至目标公众号              //3.1,下载原公众号中封面图片.判断是否存在?不存在,则下载//注:需判断文件夹是否存在?若不存在,则创建string folderName = CurrentAppInfo.AppPath + @"MaterialFilethumb";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.产品.登录器(永久免费)

 

微信小程序

版权声明

即速应用倡导尊重与保护知识产权。如发现本站文章存在版权问题,烦请提供版权疑问、身份证明、版权证明、联系方式等发邮件至197452366@qq.com ,我们将及时处理。本站文章仅作分享交流用途,作者观点不等同于即速应用观点。用户与作者的任何交易与本站无关,请知悉。

产品经理

手机 : 13312967497

擅长 : 小程序流量变现

扫码领取礼包

热门模板

  • 头条
  • 搜狐
  • 微博
  • 百家
  • 一点资讯
  • 知乎