Java编程

java使用网易云信短信验证

final static String product = “Dysmsapi”;// 短信API产品名称(短信产品名固定,无需修改)。

package util;public class StaticPeram {/ 手机验证部分配置*/// 设置超时时间-可自行调整final static String defaultConnectTimeout = “sun.net.client.defaultConnectTimeout”;final static String defaultReadTimeout = “sun.net.client.defaultReadTimeout”;final static String Timeout = “10000”;// 初始化ascClient需要的几个参数final static String product = “Dysmsapi”;// 短信API产品名称(短信产品名固定,无需修改)final static String domain = “dysmsapi.aliyuncs.com”;// 短信API产品域名(接口地址固定,无需修改)// 替换成你的AK (产品密)final static String accessKeyId = “AccessKey”;// 你的accessKeyId,填你自己的 上文配置所得 自行配置final static String accessKeySecret = “AccessKeySecret”;// 你的accessKeySecret,填你自己的 上文配置所得 自行配置// 必填:短信签名-可在短信控制台中找到final static String SignName = “短信签名”; // 阿里云配置你自己的短信签名填入// 必填:短信模板-可在短信控制台中找到final static String TemplateCode = “SMS_185840737”; // 阿里云配置你自己的短信模板CODE填入}PhoneCode.java。

java使用网易云信短信验证

$val) $string[$key] = new_addslashes($val);return $string;}……?>该文件中的函数,为全系统基础函数,可以在系统中直接调用。

package com.turing.util;import java.security.Key;import java.security.MessageDigest;import javax.crypto.Cipher;import javax.crypto.spec.IvParameterSpec;import javax.crypto.spec.SecretKeySpec;import org.apache.commons.codec.binary.Base64;/ aes加密算法* @author 图灵机器人**/public class Aes {private Key key;/ AES CBC模式使用的Initialization Vector*/private IvParameterSpec iv;/ Cipher 物件*/private Cipher cipher;/ 构造方法* @param strKet* 密钥*/public Aes(String strKey) {try {this.key = new SecretKeySpec(getHash(“MD5”, strKey), “AES”);this.iv = new IvParameterSpec(new byte[] { 0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0 });this.cipher = Cipher.getInstance(“AES/CBC/PKCS5Padding”);} catch (final Exception ex) {throw new RuntimeException(ex.getMessage());}}/ 加密方法** 说明:采用128位** @return 加密结果*/public String encrypt(String strContent) {try {byte[] data = strContent.getBytes(“UTF-8”);cipher.init(Cipher.ENCRYPT_MODE, key, iv);byte[] encryptData = cipher.doFinal(data);String encryptResult = new String(Base64.encodeBase64(encryptData), “UTF-8”);return encryptResult;} catch (Exception ex) {throw new RuntimeException(ex.getMessage());}}/* @param algorithm* @param text* @return*/private static byte[] getHash(String algorithm, String text) {try {byte[] bytes = text.getBytes(“UTF-8”);final MessageDigest digest = MessageDigest.getInstance(algorithm);digest.update(bytes);return digest.digest();} catch (final Exception ex) {throw new RuntimeException(ex.getMessage());}}}。

package com.oysd.activity;23 import java.util.List;45 import android.app.Activity;6 import android.os.Bundle;7 import android.widget.TextView;8 import android.widget.Toast;910 import com.amap.api.location.AMapLocalDayWeatherForecast;11 import com.amap.api.location.AMapLocalWeatherForecast;12 import com.amap.api.location.AMapLocalWeatherListener;13 import com.amap.api.location.AMapLocalWeatherLive;14 import com.amap.api.location.LocationManagerProxy;15 import com.oysd.ouyangmap.R;16 import com.oysd.ouyangmap.R.id;17 import com.oysd.ouyangmap.R.layout;1819 public class WeatherActivity extends Activity implements AMapLocalWeatherListener {2021 private LocationManagerProxy mLocationManagerProxy;22 private TextView tvWeather;2324 @Override25 protected void onCreate(Bundle savedInstanceState) {26 // TODO Auto-generated method stub27 super.onCreate(savedInstanceState);28 setContentView(R.layout.activity_weather);29 tvWeather = (TextView) findViewById(R.id.tv_weather);30 init();31 }3233 private void init(){34 mLocationManagerProxy = LocationManagerProxy.getInstance(this);35 mLocationManagerProxy.requestWeatherUpdates(36 LocationManagerProxy.WEATHER_TYPE_FORECAST, this);37 }3839 @Override40 public void onWeatherForecaseSearched(AMapLocalWeatherForecast aMapLocalWeatherForecast) {41 // TODO Auto-generated method stub42 if(aMapLocalWeatherForecast != null && aMapLocalWeatherForecast.getAMapException().getErrorCode() == 0){4344 List forcasts = aMapLocalWeatherForecast45 .getWeatherForecast();46 for (int i = 0; i < forcasts.size(); i++) {47 AMapLocalDayWeatherForecast forcast = forcasts.get(i);48 switch (i) {49 //今天天气50 case 0:51 //城市52 String city = forcast.getCity();53 String today = "今天 ( "+ forcast.getDate() + " )";54 String todayWeather = forcast.getDayWeather() + " "55 + forcast.getDayTemp() + "/" + forcast.getNightTemp()56 + " " + forcast.getDayWindPower();57 tvWeather.setText("城市:" + city + ", " + today + ", 天气信息:" + todayWeather);58 break;59 //明天天气60 case 1:6162 String tomorrow = "明天 ( "+ forcast.getDate() + " )";63 String tomorrowWeather = forcast.getDayWeather() + " "64 + forcast.getDayTemp() + "/" + forcast.getNightTemp()65 + " " + forcast.getDayWindPower();66 tvWeather.append("; " + tomorrow + ", 天气信息:" + tomorrowWeather);67 break;68 //后天天气69 case 2:7071 String aftertomorrow = "后天( "+ forcast.getDate() + " )";72 String aftertomorrowWeather = forcast.getDayWeather() + " "73 + forcast.getDayTemp() + "/" + forcast.getNightTemp()74 + " " + forcast.getDayWindPower();75 tvWeather.append("; " + aftertomorrow + ", 天气信息:" + aftertomorrowWeather);76 break;77 }78 }79 }else{80 // 获取天气预报失败81 Toast.makeText(this,"获取天气预报失败:"+ aMapLocalWeatherForecast.getAMapException().getErrorMessage(), Toast.LENGTH_SHORT).show();82 }8384 }8586 @Override87 public void onWeatherLiveSearched(AMapLocalWeatherLive arg0) {88 // TODO Auto-generated method stub8990 }9192 }View Code。

Similar Posts

发表评论

邮箱地址不会被公开。 必填项已用*标注