Home > Net >  Exception: entity assignment will object reference not set to an instance of an object.
Exception: entity assignment will object reference not set to an instance of an object.

Time:09-22

using System;
using System.Collections.Generic;
Using System. Linq;
using System.Text;
Using System. The Threading. The Tasks;

The namespace fk1 - FK. SendMessageService. ServiceData. MessageContent
{
Public class ArticlesItem
{
///& lt; summary>
///title
///& lt;/summary>
Public string title {get; The set; }
///& lt; summary>
///description
///& lt;/summary>
Public string description {get; The set; }
///& lt; summary>
///jump after clicking the link
///& lt;/summary>
Public string url {get; The set; }
///& lt; summary>
/news//graphic image links, support JPG, PNG format, good effect for a larger version 1068 * 455, 150 * 150 picture
///& lt;/summary>
Public string picurl {get; The set; }
}

Public class News
{
///& lt; summary>
///picture and text message, a graphic information support 1 to 8 graphic
///& lt;/summary>
Public List Articles {get; The set; }
}

Public class Send_Img
{
///& lt; summary>
///member ID list
///& lt;/summary>
Public string touser {get; The set; }
///& lt; summary>
///department ID list
///& lt;/summary>
Public string toparty {get; The set; }
///& lt; summary>
///tag ID list
///& lt;/summary>
Public string totag {get; The set; }
///& lt; summary>
///message type, fixed at this time is: the news
///& lt;/summary>
Public string msgtype {get; The set; }
///& lt; summary>
///enterprise application id of the
///& lt;/summary>
Public int agentid {get; The set; }
///& lt; summary>
///
///& lt;/summary>
Public News News {get; The set; }
///& lt; summary>
///said whether open id translated
///& lt;/summary>
Public int enable_id_trans {get; The set; }
///& lt; summary>
///indicates whether or not the open check duplicate messages, 0 means no, 1 is the default, 0
///& lt;/summary>
Public int enable_duplicate_check {get; The set; }
///& lt; Summary>
///indicates whether or not the duplicate messages check interval, the 1800 s, the biggest
no more than 4 hours///& lt;/summary>
//public int duplicate_check_interval {get; The set; }
}
}



Using FK.SendMessageService.ServiceData.Com mon;
Using Newtonsoft. Json. Linq;
using System;
using System.Collections.Generic;
Using System. Linq;
using System.Text;
Using System. The Threading. The Tasks;
Using fk1 - FK. SendMessageService. ServiceData. MessageContent;

The namespace fk1 - FK. SendMessageService. ServiceData. Send
{
Public class Send_Image: News
{
Wechat_Access_Token Toke=new Wechat_Access_Token ();

//enterprise ID
Private string Appid=ConfigHelper. GetConfigStr (" Appid ");
//application credentials keys
Private string Secret=ConfigHelper. GetConfigStr (" Secret ");
//application ID
Private int Agentid=int. Parse (ConfigHelper GetConfigStr (" Agentid "));

Public object GetSend_Image ()
{
The object json=new {};

Try
{
//1. Get access_token
String token=Toke. GetObtainToken (Appid, Secret);

If (token!="")
{
List Articleslist=new List (a);
ArticlesItem articles=new ArticlesItem ();
Articles. The title="Mid-Autumn festival gift to receive";
Articles. The description="the Mid-Autumn festival this year the company with a lavish gifts".
Articles. Url="http://23005732cx.51mypc.cn/Login.html";
Articles. Picurl="/Image/New Year card. JPG";
Articleslist. Add (articles);

Send_Img image=new Send_Img ();
Image. Touser="PengYinCong";
Image. Toparty="";
Image. Totag="";
Image. The msgtype="news";
Image. Agentid=agentid;
Image. News. Articles=articleslist;
Image. The enable_id_trans=0;
Image. The enable_duplicate_check=0;

String paramjsonStr=SerializeHelper. JsonSerialize (image);

The string Url="https://qyapi.weixin.qq.com/cgi-bin/message/send?" ;
The StringBuilder UserStr=new StringBuilder ();
UserStr. Append (Url);
UserStr. Append (" access_token="+" "+ token);

//3. Use a post request access enterprise WeChat push message interface
String UserResult=HttpUtils. DoPost (UserStr. ToString (), paramjsonStr). The ToString ();
The dynamic jsonUser=JToken. Parse (UserResult) as the dynamic;
The CreateLogManager (). The Error (" WeChat status to get the user enterprise: "+ jsonUser []" errcode ");

If (jsonUser [" errcode "]==0)
{
Json=new {Success=true, Msg="send Success"};
}
The else
{
Json=new {Success=false, Msg="failure"};
}
}
The else
{
Json=new {Success=false, Msg="access_token for failure"};
}
}
The catch (Exception ex)
{
Json=new {Success=false, Msg="abnormal"};
The CreateLogManager (). The Error (" to the enterprise WeChat user push Error message: "+ ex);
}

Return a json.
}
}
}

Abnormal unknown:

CodePudding user response:

Send_Img image=new Send_Img ();
Add one line below the
Image. The news=new news ();

CodePudding user response:

reference 1st floor is nu month god reply:
Send_Img image=new Send_Img ();
Add one line below the
Image. The news=new news (); nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  •  Tags:  
  • C#
  • Related