REST-assured 2发送文字到接口
获取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发送文字到接口的更多相关文章
- HttpClient发送get,post接口请求
HttpClient发送get post接口请求/* * post * @param url POST地址 * @param data POST数据NameValuePair[] * @retur ...
- 短信接口调用以及ajax发送短信接口实现以及前端样式
我们短信api用的是云信使平台提供的非免费短信服务:官网提供的demo有两种,分别是function加其调用.class文件加其调用. 在这里我们用class文件加调用: 首先,ThinkPHP里面自 ...
- 模拟键盘发送文字(使用SendInput函数)
嗯...老生常谈的话题, 不过系统的总结了一下, 找了个相对简单的实现方式, 可以方便的发送任何文字 参考另一片文章: http://www.cnblogs.com/-clq/archive/2011 ...
- python接口自动化(六)--发送get请求接口(详解)
简介 如果想用python做接口测试,我们首先有不得不了解和学习的模块.它就是第三方模块:Requests. 虽然Python内置的urllib模块,用于访问网络资源.但是,它用起来比较麻烦,而且,缺 ...
- dos命令批处理发送文字到剪贴板
方法一(推荐): echo 要发送到剪贴板的字 | clip 方法二: @echo off::显示要发送的文字重定向到windows临时文件夹下echo 要发送到剪贴板的字>%system ...
- 接口测试基础——第一篇smtplib发送文字邮件
现在我们就开始进入接口测试框架的知识准备阶段,今天是第一篇,很简单的,就是发送纯文字的电子邮件,会的童鞋可以忽略,不会的就多敲几遍,直到自己能敲出来为止~~ # coding: utf-8 impor ...
- [Swift通天遁地]九、拔剑吧-(10)快速创建美观的聊天界面:可发送文字、表情、图片
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...
- Android简单实现Socket通信,client连接server后,server向client发送文字数据
案例实现的是简单的Socket通信,当client(Androidclient)连接到指定server以后,server向client发送一句话文字信息(你能够拓展其他的了) 先看一下服务端程序的实现 ...
- 模拟键盘发送文字(使用SendInput API函数)
嗯...老生常谈的话题, 不过系统的总结了一下, 找了个相对简单的实现方式, 可以方便的发送任何文字 参考另一片文章: http://www.cnblogs.com/-clq/archive/2011 ...
随机推荐
- MyEclipse持续性开发教程:用JPA和Spring管理数据(四)
MyEclipse红运年货节 在线购买低至69折!火爆开抢>> [MyEclipse最新版下载] 本教程介绍了MyEclipse中的一些基于JPA / Spring的功能.有关设置JPA项 ...
- 【DevExpress v17.2新功能预告】DevExtreme ASP.NET MVC新的强类型HTML Helpers
在ASP.NET MVC中构建视图时,强类型HTML helpers非常有用.像@Html.TextBoxFor(m => m.FirstName)这样内置的Helper方法已经存在很长时间了, ...
- LibSVM文件转换为csv格式
Spark MLlib 的官方例子里面提供的数据大部分是 libsvm 格式的.这其实是一种非常蛋疼的文件格式,和常见的二维表格形式相去甚远,下图是里面的一个例子: libsvm 文件的基本格式如下: ...
- memcached集群安装与测试
1.上传安装包 libevent-2.0.22-stable.tar.gz memcached-1.4.24.tar.gz 2.安装libevent 创建目录 mkdir -p /apps/insta ...
- 配置thunderbirdmail
添加帐号 打开Edit→Account Settings ,选择左下放的 "Account actions"→"Add Mail Account". 在弹出框中 ...
- Python mode_r
f = open("例子.txt",mode="r",encoding="utf-8") print(f.read(5)) # 读取5个字符 ...
- vue2.0分页组件,
pagination.vue <!-- 表格分页组件 --> <template> <nav class="boot-nav"> <ul ...
- Linux下常用的ftp操作命令
Linux下常用的ftp操作命令 =========== 完美的分割线 ============= 1.登陆ftp服务器 ftp [IP] [PORT] # 登陆ftp服务器,本机登陆可以不写IP 实 ...
- Tensorflow 解决MNIST问题的重构程序
分为三个文件:mnist_inference.py:定义前向传播的过程以及神经网络中的参数,抽象成为一个独立的库函数:mnist_train.py:定义神经网络的训练过程,在此过程中,每个一段时间保存 ...
- MSDN Windows XP Professional x64 Edition with SP2 +VL简体中文语言包+序列号
[资源名称]---Windows XP Professional x64 Edition with SP2 - VL (English)[资源类型]---ISO镜像[资源语言]---英语+简体中文[杀 ...