开发者社区> 问答> 正文

有没有调用JSAPI的代码案例

跪求调用JSAPI的代码案例啊

展开
收起
の程序员 2015-07-30 09:15:47 4046 0
1 条回答
写回答
取消 提交回答
  • Re有没有调用JSAPI的代码案例
    C# code
      public static string getss()        
            {          

                WebRequest wrep = WebRequest.Create("https://oapi.dingtalk.com/gettoken?corpid=id&corpsecret=secret");
                WebResponse wrp = wrep.GetResponse();
                Stream strm = wrp.GetResponseStream();
                StreamReader sr = new StreamReader(strm, Encoding.UTF8);
                string jsonstr= sr.ReadToEnd();
                sr.Close();
                return jsonstr;//   {"access_token":"value","errcode":0,"errmsg":"ok"}  
            }亲测有用

    -------------------------

    Re有没有调用JSAPI的代码案例
    发送消息,亲测有用


    public string Send()
            {


                HttpWebRequest request = WebRequest.Create("https://oapi.dingtalk.com/message/send?access_token=access_token") as HttpWebRequest;

                //"{\"errcode\":40035,\"errmsg\":\"不合法的参数\"}"

                string ps = "{\"touser\":\"16|824\",\"toparty\":\"1\",\"agentid\":\"3917947\",\"msgtype\":\"text\",\"text\":{\"content\":\"this is a test memo four.\"}}";

                request.Method = "POST";

                request.ContentType = "application/json";

                request.ContentLength = Encoding.UTF8.GetByteCount(ps);

                Stream strs = request.GetRequestStream();

                StreamWriter strw = new StreamWriter(strs,Encoding.GetEncoding("GB2312"));

                strw.Write(ps);

                strw.Close();

                HttpWebResponse reponse = request.GetResponse() as HttpWebResponse;

                Stream sts = reponse.GetResponseStream();

                StreamReader sr = new StreamReader(sts,Encoding.GetEncoding("UTF-8"));

                string s = sr.ReadToEnd();

                sr.Close();
                sts.Close();
              

                return s;
            }
    2015-07-30 15:53:57
    赞同 展开评论 打赏
问答地址:
问答排行榜
最热
最新

相关电子书

更多
fibjs 模块重构从回调到协程--陈垒 立即下载
《0代码搭应用》 立即下载
不止代码 立即下载

相关实验场景

更多