获取token



https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=ID&corpsecret=SECRECT

#java
package date811;
import io.restassured.RestAssured.*;
import io.restassured.http.ContentType;
import io.restassured.matcher.RestAssuredMatchers.*;
import io.restassured.response.Response;
import org.hamcrest.Matchers.*;
import org.testng.annotations.Test;
import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.equalTo;
//assertThat方法一定要静态导入
import static org.hamcrest.Matchers.notNullValue;
import static org.junit.Assert.assertThat;
public class GetToken {
@Test
public void getToken(){
/**
* 获取access token
*/
String tokenUrl = "https://qyapi.weixin.qq.com/cgi-bin/gettoken";
String corpId = "xxxxxx";
String corpSecret = "xxxxxxx";
Response res = given().param("corpid",corpId).param("corpsecret",corpSecret).get(tokenUrl).prettyPeek();
String token_id = res.getBody().jsonPath().getString("access_token");
res.then().statusCode(equalTo(200));
assertThat(token_id,notNullValue());
}
}

发送文字到接口

#java
package date811;
import io.restassured.RestAssured.*;
import io.restassured.http.ContentType;
import io.restassured.matcher.RestAssuredMatchers.*;
import io.restassured.response.Response;
import org.hamcrest.Matchers.*;
import org.testng.annotations.Test;
import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.equalTo;
//assertThat方法一定要静态导入
import static org.hamcrest.Matchers.notNullValue;
import static org.junit.Assert.assertThat;
public class GetToken {
@Test
public void postMessage(){
/**
* 获取access token
*/
String tokenUrl = "https://qyapi.weixin.qq.com/cgi-bin/gettoken";
String corpId = "xxxxxx";
String corpSecret = "xxxxxxxxxx";
Response res = given().param("corpid",corpId).param("corpsecret",corpSecret).get(tokenUrl).prettyPeek();
String token_id = res.getBody().jsonPath().getString("access_token");
res.then().statusCode(equalTo(200));
assertThat(token_id,notNullValue()); /**
* 发送消息
* {
* "touser" : "UserID1|UserID2|UserID3",
* "toparty" : "PartyID1|PartyID2",
* "totag" : "TagID1 | TagID2",
* "msgtype" : "text",
* "agentid" : 1,
* "text" : {
* "content" : "你的快递已到,请携带工卡前往邮件中心领取。\n出发前可查看<a href=\"http://work.weixin.qq.com\">邮件中心视频实况</a>,聪明避开排队。"
* },
* "safe":0
* }
*/ String req =" {\n" +
" \"toparty\" : \"1\",\n" +
" \"msgtype\" : \"text\",\n" +
" \"agentid\" : 1,\n" +
" \"text\" : {\n" +
" \"content\" : \"你的快递已到,请携带工卡前往邮件中心领取。\\n出发前可查看<a href=\\\"http://work.weixin.qq.com\\\">邮件中心视频实况</a>,聪明避开排队。\"\n" +
" },\n" +
" \"safe\":0\n" +
" }";
/**
* 传参有2中方法:1,将参数加入URL 2.使用queryParam传入参数
*/
String post_url1 = "https://qyapi.weixin.qq.com/cgi-bin/message/send";
String post_url2 = "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token="+token_id; System.out.println("方法1");
given().contentType(ContentType.JSON).queryParam("access_token",token_id).body(req).post(post_url1).prettyPeek();
System.out.println("方法2");
given().contentType(ContentType.JSON).body(req).post(post_url2).prettyPeek();
}
}

REST-assured 2发送文字到接口的更多相关文章

  1. HttpClient发送get,post接口请求

    HttpClient发送get post接口请求/*  * post  * @param url POST地址 * @param data POST数据NameValuePair[] * @retur ...

  2. 短信接口调用以及ajax发送短信接口实现以及前端样式

    我们短信api用的是云信使平台提供的非免费短信服务:官网提供的demo有两种,分别是function加其调用.class文件加其调用. 在这里我们用class文件加调用: 首先,ThinkPHP里面自 ...

  3. 模拟键盘发送文字(使用SendInput函数)

    嗯...老生常谈的话题, 不过系统的总结了一下, 找了个相对简单的实现方式, 可以方便的发送任何文字 参考另一片文章: http://www.cnblogs.com/-clq/archive/2011 ...

  4. python接口自动化(六)--发送get请求接口(详解)

    简介 如果想用python做接口测试,我们首先有不得不了解和学习的模块.它就是第三方模块:Requests. 虽然Python内置的urllib模块,用于访问网络资源.但是,它用起来比较麻烦,而且,缺 ...

  5. dos命令批处理发送文字到剪贴板

     方法一(推荐): echo 要发送到剪贴板的字 | clip   方法二: @echo off::显示要发送的文字重定向到windows临时文件夹下echo 要发送到剪贴板的字>%system ...

  6. 接口测试基础——第一篇smtplib发送文字邮件

    现在我们就开始进入接口测试框架的知识准备阶段,今天是第一篇,很简单的,就是发送纯文字的电子邮件,会的童鞋可以忽略,不会的就多敲几遍,直到自己能敲出来为止~~ # coding: utf-8 impor ...

  7. [Swift通天遁地]九、拔剑吧-(10)快速创建美观的聊天界面:可发送文字、表情、图片

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...

  8. Android简单实现Socket通信,client连接server后,server向client发送文字数据

    案例实现的是简单的Socket通信,当client(Androidclient)连接到指定server以后,server向client发送一句话文字信息(你能够拓展其他的了) 先看一下服务端程序的实现 ...

  9. 模拟键盘发送文字(使用SendInput API函数)

    嗯...老生常谈的话题, 不过系统的总结了一下, 找了个相对简单的实现方式, 可以方便的发送任何文字 参考另一片文章: http://www.cnblogs.com/-clq/archive/2011 ...

随机推荐

  1. <NET CLR via c# 第4版>笔记 第15章 枚举类型和位标志

    15.1 枚举类型 枚举定义的符号是常量值. C#编译器编译时,会用数值替换符号,不再引用定义了符号的枚举类型.可能会出现一些版本问题. Enum.IsDefined(Type enumType, o ...

  2. ThinkPad 复刻计划 ThinkPad Time Machine

    在快节奏的高科技市场中,针对性的进化 ThinkPad 的设计几乎是闻所未闻的.在汽车行业,保时捷无疑干的不错,但我不认为有任何其他的电脑公司可以顶住压力,坚持自己的初心这么久.没有任何一个竞争对手可 ...

  3. UI基础:UITextField 分类: iOS学习-UI 2015-07-01 21:07 68人阅读 评论(0) 收藏

    UITextField 继承自UIControl,他是在UILabel基础上,对了文本的编辑.可以允许用户输入和编辑文本 UITextField的使用步骤 1.创建控件 UITextField *te ...

  4. C++ 泛型 编写的 数据结构 队列

    平时编程里经常需要用到数据结构,比如  栈和队列 等,  为了避免每次用到都需要重新编写的麻烦现将  C++ 编写的 数据结构 队列  记录下来,以备后用. 将 数据结构  队列  用头文件的形式写成 ...

  5. php-fpm配置及操作

    启动与停止 启动 /usr/local/php/sbin/php-fpm 停止 pkill php-fpm

  6. apache flink docker-compose 运行试用

    apache 是一个流处理框架,官方提供了docker 镜像,同时也提供了基于docker-compose 运行的说明 docker-compose file version: "2.1&q ...

  7. php过滤html标签截取部分内容

    <?php $str = '<span>fdsfsdf</span><a href="#">href</a>'; echo h ...

  8. vue-cli 构建项目中 config/index.js 文件解读

    // see http://vuejs-templates.github.io/webpack for documentation. var path = require('path') module ...

  9. spring4 知识点

    1 bean的 创建 1,直接在配置文件里面写一个带有@Bean注解的方法(返回值就是那个bena对象),(name等于 方法名) 2,使用 FactoryBean 接口(三个方法分别是创建,类型,单 ...

  10. drbd脑裂问题处理

    http://blog.csdn.net/heianemo/article/details/8439813 split brain实际上是指在某种情况下,造成drbd的两个节点断开了连接,都以prim ...