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

大连营销型网站建设百度推广销售员好做吗

大连营销型网站建设,百度推广销售员好做吗,政府微网站建设方案,青岛做公司网站注册的多吗目录山东鼎信API工具类随机验证码工具类进行测试Pom依赖(可以先导入依赖)创建controllerSmsServiceSmsServiceImplswagger测试(也可以使用postman)山东鼎信API工具类 山东鼎信短信官网 找到java的Api,复制下来 适当改了一下,为了调用(类名SmsUtils) p…

目录

  • 山东鼎信API工具类
  • 随机验证码工具类
  • 进行测试
    • Pom依赖(可以先导入依赖)
    • 创建controller
    • SmsService
    • SmsServiceImpl
    • swagger测试(也可以使用postman)

山东鼎信API工具类

山东鼎信短信官网
找到java的Api,复制下来
在这里插入图片描述
适当改了一下,为了调用(类名SmsUtils)

public static void sendShortMessage(String phoneNumbers,String param){String host = "http://dingxin.market.alicloudapi.com";String path = "/dx/sendSms";String method = "POST";String appcode = "你的 appcode";Map<String, String> headers = new HashMap<String, String>();//最后在header中的格式(中间是英文空格)为Authorization:APPCODE 83359fd73fe94948385f570e3c139105headers.put("Authorization", "APPCODE " + appcode);Map<String, String> querys = new HashMap<String, String>();querys.put("mobile", phoneNumbers);querys.put("param", "code:"+param);querys.put("tpl_id", "TP1711063");Map<String, String> bodys = new HashMap<String, String>();try {/*** 重要提示如下:* HttpUtils请从* https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/src/main/java/com/aliyun/api/gateway/demo/util/HttpUtils.java* 下载** 相应的依赖请参照* https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/pom.xml*/HttpResponse response = HttpUtils.doPost(host, path, method, headers, querys, bodys);System.out.println(response.toString());//获取response的body//System.out.println(EntityUtils.toString(response.getEntity()));} catch (Exception e) {e.printStackTrace();}}

代码中的appcode在控制台的云市场
在这里插入图片描述
然后会发现HttpUtils爆红,然后也给了我们提示
然后进入网址,把代码拷贝下来就行了
在这里插入图片描述

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;import org.apache.commons.lang.StringUtils;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpDelete;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpPut;
import org.apache.http.conn.ClientConnectionManager;
import org.apache.http.conn.scheme.Scheme;
import org.apache.http.conn.scheme.SchemeRegistry;
import org.apache.http.conn.ssl.SSLSocketFactory;
import org.apache.http.entity.ByteArrayEntity;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;public class HttpUtils {/*** get* * @param host* @param path* @param method* @param headers* @param querys* @return* @throws Exception*/public static HttpResponse doGet(String host, String path, String method, Map<String, String> headers, Map<String, String> querys)throws Exception {    	HttpClient httpClient = wrapClient(host);HttpGet request = new HttpGet(buildUrl(host, path, querys));for (Map.Entry<String, String> e : headers.entrySet()) {request.addHeader(e.getKey(), e.getValue());}return httpClient.execute(request);}/*** post form* * @param host* @param path* @param method* @param headers* @param querys* @param bodys* @return* @throws Exception*/public static HttpResponse doPost(String host, String path, String method, Map<String, String> headers, Map<String, String> querys, Map<String, String> bodys)throws Exception {    	HttpClient httpClient = wrapClient(host);HttpPost request = new HttpPost(buildUrl(host, path, querys));for (Map.Entry<String, String> e : headers.entrySet()) {request.addHeader(e.getKey(), e.getValue());}if (bodys != null) {List<NameValuePair> nameValuePairList = new ArrayList<NameValuePair>();for (String key : bodys.keySet()) {nameValuePairList.add(new BasicNameValuePair(key, bodys.get(key)));}UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(nameValuePairList, "utf-8");formEntity.setContentType("application/x-www-form-urlencoded; charset=UTF-8");request.setEntity(formEntity);}return httpClient.execute(request);}	/*** Post String* * @param host* @param path* @param method* @param headers* @param querys* @param body* @return* @throws Exception*/public static HttpResponse doPost(String host, String path, String method, Map<String, String> headers, Map<String, String> querys, String body)throws Exception {    	HttpClient httpClient = wrapClient(host);HttpPost request = new HttpPost(buildUrl(host, path, querys));for (Map.Entry<String, String> e : headers.entrySet()) {request.addHeader(e.getKey(), e.getValue());}if (StringUtils.isNotBlank(body)) {request.setEntity(new StringEntity(body, "utf-8"));}return httpClient.execute(request);}/*** Post stream* * @param host* @param path* @param method* @param headers* @param querys* @param body* @return* @throws Exception*/public static HttpResponse doPost(String host, String path, String method, Map<String, String> headers, Map<String, String> querys, byte[] body)throws Exception {    	HttpClient httpClient = wrapClient(host);HttpPost request = new HttpPost(buildUrl(host, path, querys));for (Map.Entry<String, String> e : headers.entrySet()) {request.addHeader(e.getKey(), e.getValue());}if (body != null) {request.setEntity(new ByteArrayEntity(body));}return httpClient.execute(request);}/*** Put String* @param host* @param path* @param method* @param headers* @param querys* @param body* @return* @throws Exception*/public static HttpResponse doPut(String host, String path, String method, Map<String, String> headers, Map<String, String> querys, String body)throws Exception {    	HttpClient httpClient = wrapClient(host);HttpPut request = new HttpPut(buildUrl(host, path, querys));for (Map.Entry<String, String> e : headers.entrySet()) {request.addHeader(e.getKey(), e.getValue());}if (StringUtils.isNotBlank(body)) {request.setEntity(new StringEntity(body, "utf-8"));}return httpClient.execute(request);}/*** Put stream* @param host* @param path* @param method* @param headers* @param querys* @param body* @return* @throws Exception*/public static HttpResponse doPut(String host, String path, String method, Map<String, String> headers, Map<String, String> querys, byte[] body)throws Exception {    	HttpClient httpClient = wrapClient(host);HttpPut request = new HttpPut(buildUrl(host, path, querys));for (Map.Entry<String, String> e : headers.entrySet()) {request.addHeader(e.getKey(), e.getValue());}if (body != null) {request.setEntity(new ByteArrayEntity(body));}return httpClient.execute(request);}/*** Delete*  * @param host* @param path* @param method* @param headers* @param querys* @return* @throws Exception*/public static HttpResponse doDelete(String host, String path, String method, Map<String, String> headers, Map<String, String> querys)throws Exception {    	HttpClient httpClient = wrapClient(host);HttpDelete request = new HttpDelete(buildUrl(host, path, querys));for (Map.Entry<String, String> e : headers.entrySet()) {request.addHeader(e.getKey(), e.getValue());}return httpClient.execute(request);}private static String buildUrl(String host, String path, Map<String, String> querys) throws UnsupportedEncodingException {StringBuilder sbUrl = new StringBuilder();sbUrl.append(host);if (!StringUtils.isBlank(path)) {sbUrl.append(path);}if (null != querys) {StringBuilder sbQuery = new StringBuilder();for (Map.Entry<String, String> query : querys.entrySet()) {if (0 < sbQuery.length()) {sbQuery.append("&");}if (StringUtils.isBlank(query.getKey()) && !StringUtils.isBlank(query.getValue())) {sbQuery.append(query.getValue());}if (!StringUtils.isBlank(query.getKey())) {sbQuery.append(query.getKey());if (!StringUtils.isBlank(query.getValue())) {sbQuery.append("=");sbQuery.append(URLEncoder.encode(query.getValue(), "utf-8"));}        			}}if (0 < sbQuery.length()) {sbUrl.append("?").append(sbQuery);}}return sbUrl.toString();}private static HttpClient wrapClient(String host) {HttpClient httpClient = new DefaultHttpClient();if (host.startsWith("https://")) {sslClient(httpClient);}return httpClient;}private static void sslClient(HttpClient httpClient) {try {SSLContext ctx = SSLContext.getInstance("TLS");X509TrustManager tm = new X509TrustManager() {public X509Certificate[] getAcceptedIssuers() {return null;}public void checkClientTrusted(X509Certificate[] xcs, String str) {}public void checkServerTrusted(X509Certificate[] xcs, String str) {}};ctx.init(null, new TrustManager[] { tm }, null);SSLSocketFactory ssf = new SSLSocketFactory(ctx);ssf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);ClientConnectionManager ccm = httpClient.getConnectionManager();SchemeRegistry registry = ccm.getSchemeRegistry();registry.register(new Scheme("https", 443, ssf));} catch (KeyManagementException ex) {throw new RuntimeException(ex);} catch (NoSuchAlgorithmException ex) {throw new RuntimeException(ex);}}
}

随机验证码工具类

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Random;/*** 获取随机数* * @author qianyi**/
public class RandomUtil {private static final Random random = new Random();private static final DecimalFormat fourdf = new DecimalFormat("0000");private static final DecimalFormat sixdf = new DecimalFormat("000000");public static String getFourBitRandom() {return fourdf.format(random.nextInt(10000));}public static String getSixBitRandom() {return sixdf.format(random.nextInt(1000000));}/*** 给定数组,抽取n个数据* @param list* @param n* @return*/public static ArrayList getRandom(List list, int n) {Random random = new Random();HashMap<Object, Object> hashMap = new HashMap<Object, Object>();// 生成随机数字并存入HashMapfor (int i = 0; i < list.size(); i++) {int number = random.nextInt(100) + 1;hashMap.put(number, i);}// 从HashMap导入数组Object[] robjs = hashMap.values().toArray();ArrayList r = new ArrayList();// 遍历数组并打印数据for (int i = 0; i < n; i++) {r.add(list.get((int) robjs[i]));System.out.print(list.get((int) robjs[i]) + "\t");}System.out.print("\n");return r;}
}

进行测试

Pom依赖(可以先导入依赖)

    <dependencies><dependency><groupId>com.alibaba</groupId><artifactId>fastjson</artifactId><version>1.2.15</version></dependency><dependency><groupId>org.apache.httpcomponents</groupId><artifactId>httpclient</artifactId><version>4.2.1</version></dependency><dependency><groupId>org.apache.httpcomponents</groupId><artifactId>httpcore</artifactId><version>4.2.1</version></dependency><dependency><groupId>commons-lang</groupId><artifactId>commons-lang</artifactId><version>2.6</version></dependency></dependencies>

创建controller

import com.donglin.commonutils.R;
import com.donglin.smsservice.service.SmsService;
import com.donglin.smsservice.utils.RandomUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import java.util.concurrent.TimeUnit;@Api(description = "短息发送")
@RestController
@RequestMapping("/edusms/sms")
@CrossOrigin //跨域
public class SmsApiController {@Autowiredprivate SmsService smsService;@Autowiredprivate RedisTemplate<String,String> redisTemplate;@ApiOperation(value = "短信发送")@GetMapping("send/{phone}")public R sendSmsPhone(@PathVariable String phone){String code = redisTemplate.opsForValue().get(phone);if(!StringUtils.isEmpty(code))return R.ok();code = RandomUtil.getFourBitRandom();boolean isSend = smsService.send(phone, code);if(isSend) {redisTemplate.opsForValue().set(phone, code,5, TimeUnit.MINUTES);return R.ok();} else {return R.error().message("发送短信失败");}}
}

SmsService

public interface SmsService {boolean send(String phone, String code);
}

SmsServiceImpl

import com.donglin.smsservice.service.SmsService;
import com.donglin.smsservice.utils.SmsUtils;
import org.springframework.stereotype.Service;import java.rmi.ServerException;@Service
public class SmsServiceImpl implements SmsService {@Overridepublic boolean send(String phone, String code) {try {SmsUtils.sendShortMessage(phone,code);System.out.println("phone = " + phone);System.out.println("code = " + code);return true;} catch (Exception e) {e.printStackTrace();return false;}}
}

swagger测试(也可以使用postman)

在这里插入图片描述


文章转载自:
http://rankine.mkbc.cn
http://characterisation.mkbc.cn
http://eyas.mkbc.cn
http://encomiastic.mkbc.cn
http://updatable.mkbc.cn
http://pastina.mkbc.cn
http://larkishness.mkbc.cn
http://captive.mkbc.cn
http://waterline.mkbc.cn
http://preventer.mkbc.cn
http://prudence.mkbc.cn
http://visiting.mkbc.cn
http://diaphragmatic.mkbc.cn
http://sasquatch.mkbc.cn
http://cecity.mkbc.cn
http://around.mkbc.cn
http://polysaprobe.mkbc.cn
http://timberyard.mkbc.cn
http://sika.mkbc.cn
http://overstrain.mkbc.cn
http://paterfamilias.mkbc.cn
http://smaze.mkbc.cn
http://bso.mkbc.cn
http://clindamycin.mkbc.cn
http://outshoot.mkbc.cn
http://nomistic.mkbc.cn
http://boomtown.mkbc.cn
http://roundish.mkbc.cn
http://epagogic.mkbc.cn
http://galgenhumor.mkbc.cn
http://landway.mkbc.cn
http://fritillary.mkbc.cn
http://zoophobia.mkbc.cn
http://graphologist.mkbc.cn
http://philodendron.mkbc.cn
http://nobby.mkbc.cn
http://withdraw.mkbc.cn
http://poussin.mkbc.cn
http://septum.mkbc.cn
http://photology.mkbc.cn
http://ladino.mkbc.cn
http://yami.mkbc.cn
http://system.mkbc.cn
http://pneumatolysis.mkbc.cn
http://bassoonist.mkbc.cn
http://pentium.mkbc.cn
http://flexile.mkbc.cn
http://hypermetropia.mkbc.cn
http://apf.mkbc.cn
http://absorbing.mkbc.cn
http://pbb.mkbc.cn
http://compandor.mkbc.cn
http://likable.mkbc.cn
http://paperbacked.mkbc.cn
http://graz.mkbc.cn
http://fantom.mkbc.cn
http://protonephridium.mkbc.cn
http://christianize.mkbc.cn
http://playback.mkbc.cn
http://nuncle.mkbc.cn
http://confined.mkbc.cn
http://mothering.mkbc.cn
http://manicheism.mkbc.cn
http://uvular.mkbc.cn
http://fright.mkbc.cn
http://drivability.mkbc.cn
http://verst.mkbc.cn
http://monestrous.mkbc.cn
http://rodlet.mkbc.cn
http://loathe.mkbc.cn
http://seminude.mkbc.cn
http://devanagari.mkbc.cn
http://ishmael.mkbc.cn
http://refire.mkbc.cn
http://sociologism.mkbc.cn
http://everywhen.mkbc.cn
http://recognitory.mkbc.cn
http://b2b.mkbc.cn
http://ungraceful.mkbc.cn
http://trail.mkbc.cn
http://geneva.mkbc.cn
http://wooftah.mkbc.cn
http://construe.mkbc.cn
http://globefish.mkbc.cn
http://monosepalous.mkbc.cn
http://sheridan.mkbc.cn
http://shaddock.mkbc.cn
http://sard.mkbc.cn
http://lsu.mkbc.cn
http://hollands.mkbc.cn
http://hydrosome.mkbc.cn
http://conference.mkbc.cn
http://heterophile.mkbc.cn
http://ramadan.mkbc.cn
http://foamless.mkbc.cn
http://appaloosa.mkbc.cn
http://pavulon.mkbc.cn
http://corrasive.mkbc.cn
http://gate.mkbc.cn
http://increased.mkbc.cn
http://www.15wanjia.com/news/64819.html

相关文章:

  • 乐清柳市阿里巴巴做网站的长安网站优化公司
  • 网上做试卷的网站深圳营销型网站定制
  • 网站注销备案查询系统seo技术分享博客
  • 在阿里怎样做单页销售网站贵州seo学校
  • 高端网站建设服务会计培训班初级费用
  • 什么网站做h5做得好品牌传播推广方案
  • 网站如何做导航条网站排行
  • app制作软件下载官网哪里可以学seo课程
  • 北京网站备案速度网站提交工具
  • 贵港网站制作域名关键词查询
  • 互联网保险的发展seo策略什么意思
  • 化妆品网站的设计与实现做推广哪个平台效果好
  • 三明网站制作抖音广告
  • 微博内网站怎么做的湖北百度seo排名
  • 建立网站wordpress谷歌aso优化
  • 网站开发实验报告模版成都排名推广
  • 手把手教建设网站win10优化大师是官方的吗
  • 武汉设计工程学院招生信息网山东搜索引擎优化
  • 实力网站建设郑州seo
  • 设计外贸商城网站建设免费独立站自建站网站
  • 网站建设培训哪个好免费个人网站模板
  • 广西住房和城乡建设厅官网桂建云北京搜索引擎优化主管
  • 怎么做简单的网站百度网盘搜索引擎入口在哪里
  • 扬州做网站多少钱搜狗网站收录提交入口
  • 宝安区建设交易网站站长素材网站
  • 网站怎么做拉新百家号seo
  • 物流公司网站建设方案电商网站平台有哪些
  • 理财网站如何做推广宁波免费建站seo排名
  • 政府网站建设广告投放平台排名
  • 为什么要网站备案2023年国际新闻大事件10条