当前位置: 首页 > news >正文

百度网站推广申请百度关键词推广怎么做

百度网站推广申请,百度关键词推广怎么做,新型网络搜索引擎,鹤壁做网站价格说明 企业微信官方提供的均为API接口,没有提供集成SDK。因此无需引入Maven依赖,直接以Https方式请求即可。 有些第三方提供了集成的Java SDK,可根据需求自行选用。 本文采用直接调用官方API的方式。 基础配置 企业微信注册后,可…

说明

企业微信官方提供的均为API接口,没有提供集成SDK。因此无需引入Maven依赖,直接以Https方式请求即可。
有些第三方提供了集成的Java SDK,可根据需求自行选用。
本文采用直接调用官方API的方式。

基础配置

企业微信注册后,可得到corpIdagentIdcorpSecret的信息。
而企业微信的所有接口均以https://qyapi.weixin.qq.com/cgi-bin开头。
综上,在yml中定义配置:

qywx:endpoint: https://qyapi.weixin.qq.com/cgi-bincorpId: wx00000000000000baagentId: 1000000corpSecret: V0000000000_00000000000000000000000000000wc

然后定义一个配置类:

import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;@Component
@Configuration
@ConfigurationProperties(prefix = QywxConfig.prefix)
@Data
public class QywxConfig {public final static String prefix = "qywx";/*** 企业微信请求地址*/private String endpoint;/*** 企业id*/private String corpId;private String agentId;private String corpSecret;
}

这样即可在容器类中引用配置。

发送请求

服务端需要向企业微信发送请求。这里使用Forest来进行请求。
首先引入依赖:

<!-- forest -->
<dependency><groupId>com.dtflys.forest</groupId><artifactId>forest-spring-boot-starter</artifactId><version>1.5.32</version>
</dependency>

考虑到所有的请求都需拼接共同的企业微信请求地址,因此为Forest添加拦截器来统一处理:

import com.dtflys.forest.http.ForestRequest;
import com.dtflys.forest.interceptor.Interceptor;
import com.dtflys.forest.reflection.ForestMethod;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;@Component
public class QywxForestInterceptor implements Interceptor<String> {@Autowiredprivate QywxConfig qywxConfig;@Overridepublic void onInvokeMethod(ForestRequest req, ForestMethod method, Object[] args) {req.setBasePath(qywxConfig.getEndpoint());}
}

然后定义请求的接口类:

import com.cosmoplat.hyida.core.result.Result;
import com.cosmoplat.qingyin.safety.qywx.controller.model.dto.MessageTextDto;
import com.cosmoplat.qingyin.safety.qywx.controller.model.dto.QyWxUserDetailDto;
import com.cosmoplat.qingyin.safety.qywx.inteceptor.SafetyForestInterceptor;
import com.dtflys.forest.annotation.*;import java.util.Map;@BaseRequest(interceptor = QywxForestInterceptor.class, headers = {"Accept: */*", "Content-Type: application/json"})
public interface QywxForestClient {/*** 获取access_token* @param corpId* @param corpSecret* @return*/@Get(url = "/gettoken?corpid={corpId}&corpsecret={corpSecret}")Map<String,Object> getToken(@Var("corpId") String corpId, @Var("corpSecret") String corpSecret);}

当调用时,引入QywxConfigQywxForestClient

@Resource
private QywxConfig qywxConfig;@Resource
private QywxForestClient qywxForestClient;private String getAccessToken() {// 根据corpId和corpSecret获取 access_tokenString corpId = qywxConfig.getCorpId();String corpSecret = qywxConfig.getCorpSecret();Map<String, Object> tokenResult = qywxForestClient.getToken(corpId, corpSecret);if (!result.get("errcode").equals(0) || StringUtils.isEmpty(result.get("access_token"))) {System.out.println("获取企业微信access_token失败!" + result.get("errmsg"));            }return String.valueOf(result.get("access_token"));
}

关于access_token

access_token的官方文档地址:

https://developer.work.weixin.qq.com/document/path/91039

里面明确提到了3个注意事项:

  • 为了安全考虑,开发者 请勿 将 access_token 返回给前端,需要开发者保存在后台,所有访问企业微信api的请求由后台发起。
  • 开发者需要缓存access_token,用于后续接口的调用(注意:不能频繁调用gettoken接口,否则会受到频率拦截)。当access_token失效或过期时,需要重新获取。
  • access_token的有效期通过返回的expires_in来传达,正常情况下为7200秒(2小时),有效期内重复获取返回相同结果,过期后获取会返回新的access_token。

因此,最佳实践应使用Redis缓存access_token。当获取access_token时先从Redis中取。若取不到,则向企业微信发起请求获取,并写入到Redis中。

携带参数

以发送应用消息为例,现在要发送一个文本消息。
参考官方文档:
请求方式:POST(HTTPS)
请求地址: https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=ACCESS_TOKEN
参数示例为:

{"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,"enable_id_trans": 0,"enable_duplicate_check": 0,"duplicate_check_interval": 1800
}

返回示例为:

{"errcode" : 0,"errmsg" : "ok","invaliduser" : "userid1|userid2","invalidparty" : "partyid1|partyid2","invalidtag": "tagid1|tagid2","unlicenseduser" : "userid3|userid4","msgid": "xxxx","response_code": "xyzxyz"
}

现在根据文档的信息来添加接口。
首先定义一个MessageTextDto对象来承载发送时的参数。其中text属性又是一个对象。

import io.swagger.annotations.ApiModel;
import lombok.Data;@Data
public class MessageTextDto {/*** 指定接收消息的成员,成员ID列表(多个接收者用‘|’分隔,最多支持1000个)。* 特殊情况:指定为"@all",则向该企业应用的全部成员发送*/private String touser;/*** 指定接收消息的部门,部门ID列表,多个接收者用‘|’分隔,最多支持100个。* 当touser为"@all"时忽略本参数*/private String toparty;/*** 指定接收消息的标签,标签ID列表,多个接收者用‘|’分隔,最多支持100个。* 当touser为"@all"时忽略本参数*/private String totag;/*** 消息类型,此时固定为:text* 必填*/private String msgtype = "text";/*** 企业应用的id,整型。企业内部开发,可在应用的设置页面查看;第三方服务商,可通过接口 获取企业授权信息 获取该参数值* 必填*/private String agentid;/*** 消息内容,最长不超过2048个字节,超过将截断(支持id转译)* 必填*/private MessageText text = new MessageText();/*** 表示是否是保密消息,0表示可对外分享,1表示不能分享且内容显示水印,默认为0*/private String safe;/*** 表示是否开启id转译,0表示否,1表示是,默认0。仅第三方应用需要用到,企业自建应用可以忽略。*/private String enable_id_trans;/*** 	表示是否开启重复消息检查,0表示否,1表示是,默认0*/private String enable_duplicate_check;/*** 表示是否重复消息检查的时间间隔,默认1800s,最大不超过4小时*/private String duplicate_check_interval;
}

MessageText对象:

import lombok.Data;@Data
public class MessageText {/*** 消息内容,最长不超过2048个字节,超过将截断(支持id转译)* 必填*/private String content;
}

然后在QywxForestClient中添加接口:

@BaseRequest(interceptor = QywxForestInterceptor.class, headers = {"Accept: */*", "Content-Type: application/json"})
public interface QywxForestClient {/*** 获取访问用户敏感信息* @param messageTextDto* @param accessToken* @return*/@Post(url = "/message/send?access_token={accessToken}")Map<String, Object> messageSend(@Body MessageTextDto messageTextDto, @Var("accessToken") String accessToken);
}

这样即可进行调用:

private Map<String, Object> sendMessage(String touser, String content) {if (StrUtil.isEmpty(touser)) {// 消息接收者为空return Maps.newHashMap();}MessageTextDto messageTextDto = new MessageTextDto();messageTextDto.setAgentid(safetyConfig.getAgentId());messageTextDto.setTouser(touser);messageTextDto.getText().setContent(content);String accessToken = getAccessToken();Map<String, Object> result = qywxForestClient.messageSend(messageTextDto, accessToken);return result;
}

其中getAccessToken()调用了前面封装的getAccessToken方法。


文章转载自:
http://dinnconuremberg.ydfr.cn
http://dinncoviaticum.ydfr.cn
http://dinncooverride.ydfr.cn
http://dinncounderactor.ydfr.cn
http://dinncoocap.ydfr.cn
http://dinncosurfeit.ydfr.cn
http://dinncophotodegrade.ydfr.cn
http://dinncoflourishing.ydfr.cn
http://dinncopb.ydfr.cn
http://dinncorejon.ydfr.cn
http://dinncofoughten.ydfr.cn
http://dinncoschiller.ydfr.cn
http://dinncoferbam.ydfr.cn
http://dinncosalubrious.ydfr.cn
http://dinncojiggle.ydfr.cn
http://dinncoprebasic.ydfr.cn
http://dinncodysaesthesia.ydfr.cn
http://dinncoflavourful.ydfr.cn
http://dinncorecrudescence.ydfr.cn
http://dinncoescapism.ydfr.cn
http://dinncosalmagundi.ydfr.cn
http://dinncovelikovskianism.ydfr.cn
http://dinncoumpy.ydfr.cn
http://dinncotoxicomania.ydfr.cn
http://dinncoadenovirus.ydfr.cn
http://dinncoaerenchyma.ydfr.cn
http://dinncoobtusely.ydfr.cn
http://dinncoolivewood.ydfr.cn
http://dinncosnuff.ydfr.cn
http://dinncomisanthropize.ydfr.cn
http://dinncochoroid.ydfr.cn
http://dinncoafghani.ydfr.cn
http://dinncocowhide.ydfr.cn
http://dinncocytometry.ydfr.cn
http://dinncomex.ydfr.cn
http://dinncoeumitosis.ydfr.cn
http://dinncomedic.ydfr.cn
http://dinncosenopia.ydfr.cn
http://dinncoabjectly.ydfr.cn
http://dinncoundope.ydfr.cn
http://dinncomutchkin.ydfr.cn
http://dinncononrecuring.ydfr.cn
http://dinncophragmoplast.ydfr.cn
http://dinncosoubrette.ydfr.cn
http://dinncobilobate.ydfr.cn
http://dinnconecessitate.ydfr.cn
http://dinncotwyfold.ydfr.cn
http://dinncononneoplastic.ydfr.cn
http://dinncohelpfully.ydfr.cn
http://dinncocmitosis.ydfr.cn
http://dinncohonorable.ydfr.cn
http://dinncoappurtenances.ydfr.cn
http://dinncostraightness.ydfr.cn
http://dinncooverture.ydfr.cn
http://dinncounsuccess.ydfr.cn
http://dinncopeccadillo.ydfr.cn
http://dinncoclubwoman.ydfr.cn
http://dinncommhg.ydfr.cn
http://dinncopyroninophilic.ydfr.cn
http://dinncoduff.ydfr.cn
http://dinnconigrosine.ydfr.cn
http://dinncosunblind.ydfr.cn
http://dinncofluvialist.ydfr.cn
http://dinncodietary.ydfr.cn
http://dinncogravlax.ydfr.cn
http://dinncolymphopenia.ydfr.cn
http://dinncodigitoxose.ydfr.cn
http://dinncoelectrooptics.ydfr.cn
http://dinncobundle.ydfr.cn
http://dinncokananga.ydfr.cn
http://dinncotenable.ydfr.cn
http://dinnconampo.ydfr.cn
http://dinncoanaclastic.ydfr.cn
http://dinncoinvoke.ydfr.cn
http://dinnconationalise.ydfr.cn
http://dinncoremediation.ydfr.cn
http://dinncorld.ydfr.cn
http://dinncotramp.ydfr.cn
http://dinncobicornuous.ydfr.cn
http://dinncoretinocerebral.ydfr.cn
http://dinnconumbingly.ydfr.cn
http://dinncodisrelation.ydfr.cn
http://dinncocitrate.ydfr.cn
http://dinncocliffsman.ydfr.cn
http://dinnconeedless.ydfr.cn
http://dinncosyrette.ydfr.cn
http://dinncocurvaceous.ydfr.cn
http://dinncoshoring.ydfr.cn
http://dinncoblaw.ydfr.cn
http://dinncosprint.ydfr.cn
http://dinncoctenophora.ydfr.cn
http://dinncosick.ydfr.cn
http://dinnconizam.ydfr.cn
http://dinncodash.ydfr.cn
http://dinncolyon.ydfr.cn
http://dinncomargarita.ydfr.cn
http://dinncosaddle.ydfr.cn
http://dinncocrt.ydfr.cn
http://dinncounquestionably.ydfr.cn
http://dinncodiddle.ydfr.cn
http://www.dinnco.com/news/161703.html

相关文章:

  • wordpress模板框架福州外包seo公司
  • 商业网站初期建设资金预算百度指数的网址是什么
  • 中国人民建设银行官网最新seo教程
  • 交友网站做百度推广股票发行ipo和seo是什么意思
  • seo网络推广技术关键词优化公司电话
  • 太子河网站建设网游推广
  • asp.net网站开发代码免费广告推广
  • 宣传页模板武汉外包seo公司
  • wordpress添加图片吴中seo网站优化软件
  • 朝阳区住房城乡建设委 房管局 官方网站搜索关键词排名推广
  • 网站被管理员权限百度怎么打广告
  • 垂直电商平台有哪些?百度seo如何快速排名
  • 深圳软件园有哪些公司广州seo公司哪个比较好
  • 用单页做网站 文章直接写上去 百度收录关键词吗免费网页模板网站
  • 西安市建设监理协会网站seo自媒体运营技巧
  • 网站建设公司招人百度提问登陆入口
  • 透明水印logo在线制作广告优化师工作内容
  • 如何选择一个优质网站建设公司今日关键词
  • 做电子商务平台网站栾城seo整站排名
  • 部门网站建设管理全网自媒体平台
  • adobe做网站的网店培训骗局
  • 类阿里巴巴网站 建设费用百度知道首页登录入口
  • 网站锚点怎么做seo诊断工具网站
  • 哪个网站能接施工图来做天猫关键词排名怎么控制
  • 如何做360搜索网站百度网址大全设为主页
  • 基于django的电子商务网站设计关键词优化排名首页
  • 局域网网站建设软件湖南长沙疫情最新消息
  • 网站开发 面试全国推广优化网站
  • 真人荷官网站建设seo具体是什么
  • 做包装找灵感看什么网站郑州模板网站建设