获取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. 去掉“Windows文件保护”

    1.在“开始→运行”对话框中键入“gpedit.msc”,打开“本地计算机策略→计算机配置→管理模板→系统”窗口,找到“Windows文件保护”组,在右侧窗格中双击“设置Windows文件保护扫描”项 ...

  2. firefox下reset()不好使的问题

    最近在测试项目时发现,在firefox下,form.reset()方法对于隐藏的<input>等不起效果,导致程序中出现了错误,以下面为例: js代码: document.agentFor ...

  3. 安装Linux Mint17

    韩总有台笔记本之前安装的是Win7,结果被她用成含毒,含马的机器了,最后干脆机器操作不了,愤怒的韩总把戴尔骂了个痛快并保证以后再也不用戴尔的笔记本了,然后愉快的换了一台新电脑,这台机器便放在我这里没人 ...

  4. MySQL Performance Tuning: Tips, Scripts and Tools

    With MySQL, common configuration mistakes can cause serious performance problems. In fact, if you mi ...

  5. SWIFT中切換UIContainerView內的Controller

    如下,一个UIContainerView内切换两个Controller,当点击登录的时候UIContainerView的视图为LoginController,当点击登记的时候UIContainerVi ...

  6. 《Effective Python:编写高质量Python代码的59个有效方法》读书笔记(完结)

    Effective Python 第1章 用Pythonic方式来思考 be pythonic 遵守pep8 python3有两种字符序列类型:bytes(原始的字节)和str(Unicode字符). ...

  7. 50个必备常用的jQuery代码段

    1. 如何修改jQuery默认编码(例如默认UTF-8改成改GB2312): $.ajaxSetup({ ajaxSettings:{ contentType:"application/x- ...

  8. magento建立多语言网站

    默认Magento仅仅有English语言包,所以如果想也显示中文,就要安装中文语言包. 步骤: 1. 首先,去http://www.magentocommerce.com/langs/list/下载 ...

  9. tiny4412 UART for C printf Demo

    /************************************************************************** * tiny4412 UART for C pr ...

  10. TensorRT简介-转载

    前言 NVIDIA TensorRT是一种高性能神经网络推理(Inference)引擎,用于在生产环境中部署深度学习应用程序,应用有 图像分类.分割和目标检测等,可提供最大的推理吞吐量和效率.Tens ...