下面就以php语言为例为大家介绍下短信接口如何

2019-11-26 12:36栏目:美高梅开户送58元官网
TAG:

1. 短信调用class

图片 1

private int readMissCall() { 
  int result = 0; 
  Cursor cursor = getContentResolver().query(CallLog.Calls.CONTENT_URI, new String[] { 
      Calls.TYPE 
    }, " type=? and new=?", new String[] { 
        Calls.MISSED_TYPE + "", "1" 
    }, "date desc"); 

  if (cursor != null) { 
    result = cursor.getCount(); 
    cursor.close(); 
  } 
  return result; 
} 
require 'sms.php';$sms = new Sms( array('api_key' => '86f52f3ce0647dc24da53eafe29fadd4' , 'use_ssl' => FALSE ) ); //send 单发接口$res = $sms->send_batch , '验证码:19272{ if( isset && $res['error'] == 0 ){ echo 'success'; }else{ echo 'failed,code:'.$res['error'].',msg:'.$res['msg']; }}else{ var_dump;}exit;

.

功能代码如下:

4.获取余额示例

说明:

private ContentObserver newMmsContentObserver = new ContentObserver(new Handler()) { 
  public void onChange(boolean selfChange) { 
    int mNewSmsCount = getNewSmsCount() + getNewMmsCount(); 
  } 
}; 
private void registerObserver() { 
  unregisterObserver(); 
  getContentResolver().registerContentObserver(Uri.parse("content://sms"), true, 
      newMmsContentObserver); 
  getContentResolver().registerContentObserver(MmsSms.CONTENT_URI, true, 
      newMmsContentObserver); 
} 
private synchronized void unregisterObserver() { 
  try { 
    if (newMmsContentObserver != null) { 
      getContentResolver().unregisterContentObserver(newMmsContentObserver); 
    } 
    if (newMmsContentObserver != null) { 
      getContentResolver().unregisterContentObserver(newMmsContentObserver); 
    } 
  } catch (Exception e) { 
    Log.e(TAG, "unregisterObserver fail"); 
  } 
} 
//send 单发接口 require 'sms.php';$sms = new Sms( array('api_key' => '86f52f3ce0647dc24da53eafe29fadd4' , 'use_ssl' => FALSE ) );$res = $sms->send_batch , '验证码:19272{ if( isset && $res['error'] == 0 ){ echo 'success'; }else{ echo 'failed,code:'.$res['error'].',msg:'.$res['msg']; }}else{ var_dump;}exit;

1、注册短信接口平台账户:http://www.lx598.com/acc/x5?i=110792

private int getNewMmsCount() { 
  int result = 0; 
  Cursor csr = getContentResolver().query(Uri.parse("content://mms/inbox"), 
      null, "read = 0", null, null); 
  if (csr != null) { 
    result = csr.getCount(); 
    csr.close(); 
  } 
  return result; 
} 
 '//www.jb51.net/v1/send.json', 'send_batch' => '//www.jb51.net/v1/send_batch.json', 'status' => '//www.jb51.net/v1/status.json', ); private $_api_url = array( 'send' => '//www.jb51.net/v1/send.json', 'send_batch' => '//www.jb51.net/send_batch.json', 'status' => '//www.jb51.net/v1/status.json', ); /** * @param array $param 配置参数 * api_key api秘钥,在luosimao短信后台短信->触发发送下面可查看 * use_ssl 启用HTTPS地址,HTTPS有一定性能损耗,可选,默认不启用 */ public function __construct{ if( !isset ){ die; } if( isset ){ $this->_api_key = $param['api_key']; } if( isset ){ $this->_use_ssl = $param['use_ssl']; } } //触发,单发,适用于验证码,订单触发提醒类 public function send( $mobile , $message = '' ){ $api_url = !$this->_use_ssl ? $this->_api_url['send'] : $this->_ssl_api_url['send']; $param = array( 'mobile' => $mobile , 'message' => $message, ); $res = $this->http_post; return @json_decode; } //批量发送,用于大批量发送 public function send_batch( $mobile_list = array() , $message = array{ $api_url = !$this->_use_ssl ? $this->_api_url['send_batch'] : $this->_ssl_api_url['send_batch']; $mobile_list = is_array ? implode : $mobile_list; $param = array( 'mobile_list' => $mobile_list , 'message' => $message, 'time' => $time, ); $res = $this->http_post; return @json_decode; } //获取短信账号余额 public function get_deposit(){ $api_url = !$this->_use_ssl ? $this->_api_url['status'] : $this->_ssl_api_url['status']; $res = $this->http_get; return @json_decode; } /** * @param string $type 接收类型,用于在服务器端接收上行和发送状态,接收地址需要在luosimao后台设置 * @param array $param 传入的参数,从推送的url中获取,官方文档:https://luosimao.com/docs/api/ */ public function recv( $type = 'status' , $param = array{ if{ if( $param['batch_id'] && $param['mobile'] && $param['status'] ){ //状态 // do record } }elseif( $type == 'incoming' ){ //上行回复 if( $param['mobile'] && $param['message'] ){ // do record } } } /** * @param string $api_url 接口地址 * @param array $param post参数 * @param int $timeout 超时时间 * @return bool */ private function http_post( $api_url = '' , $param = array{ if{ die; } $ch = curl_init(); curl_setopt( $ch, CURLOPT_URL, $api_url ); curl_setopt( $ch, CURLOPT_HTTP_VERSION , CURL_HTTP_VERSION_1_0 ); curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, $timeout ); curl_setopt( $ch, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt( $ch, CURLOPT_HEADER, FALSE); if( parse_url['scheme'] == 'https' ){ curl_setopt($ch, CURLOPT_SSL_VERIFYHOST , FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER , FALSE); } curl_setopt( $ch, CURLOPT_HTTPAUTH , CURLAUTH_BASIC); curl_setopt( $ch, CURLOPT_USERPWD , 'api:key-'.$this->_api_key ); curl_setopt( $ch, CURLOPT_POST, TRUE); curl_setopt( $ch, CURLOPT_POSTFIELDS, $param ); $res = curl_exec; $error = curl_error; curl_close{ $this->_last_error[] = $error; return FALSE; } return $res; } /** * @param string $api_url 接口地址 * @param string $timeout 超时时间 * @return bool */ private function http_get( $api_url = '' , $timeout = '' ){ if{ die; } $ch = curl_init(); curl_setopt( $ch, CURLOPT_URL, $api_url ); curl_setopt( $ch, CURLOPT_HTTP_VERSION , CURL_HTTP_VERSION_1_0 ); curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, $timeout ); curl_setopt( $ch, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt( $ch, CURLOPT_HEADER, FALSE); if( parse_url['scheme'] == 'https' ){ curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST , FALSE); curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER , FALSE); } curl_setopt( $ch, CURLOPT_HTTPAUTH , CURLAUTH_BASIC); curl_setopt( $ch, CURLOPT_USERPWD , 'api:key-'.$this->_api_key ); $res = curl_exec; $error = curl_error; curl_close{ $this->_last_error[] = curl_error; return FALSE; } return $res; } public function last_error(){ return $this->_last_error; }}

2、请求地址

得到未读短信数量:

3.批量发送示例

1;发送成功!;61;0;61;3660;12024380;

本文实例展示了Android实现获取未接来电和未读短信数量的方法,在Android程序开发中非常常见,是非常实用的功能,现分享给大家供大家参考。具体如下:

以上就是本文的全部内容,希望对大家的学习有所帮助。

4、发送响应Json格式

广播只是当有新的未接来电时才会发送,但是如果有旧的未接来电没有读取时,上面的广播就得不到数据了,那就必须得从数据库中查找了。

//deposit 余额查询require 'sms.php';$sms = new Sms( array('api_key' => '86f52f3ce0647dc24da53eafe29fadd4' , 'use_ssl' => FALSE ) ); $res = $sms->get_deposit{ if( isset && $res['error'] == 0 ){ echo 'desposit:'.$res['deposit']; }else{ echo 'failed,code:'.$res['error'].',msg:'.$res['msg']; }}else{ var_dump;}exit;

http请求都应以POST形式提交,编码为UTF-8

final IntentFilter filter = new IntentFilter(); 
filter.addAction("com.android.phone.NotificationMgr.MissedCall_intent"); 
final Application application = getApplication(); 
application.registerReceiver(new BroadcastReceiver() { 
  @Override 
  public void onReceive(Context context, Intent intent) { 
    String action = intent.getAction(); 
    if (action != null && "com.android.phone.NotificationMgr.MissedCall_intent".equals(action)) { 
      int mMissCallCount = intent.getExtras().getInt("MissedCallNumber"); 
    } 
  } 
}, filter); 

本文实例为大家分享了几个常用的php短信接口代码,供大家参考,具体内容如下

具体功能代码如下:

2.短信发送示例

发送普通短信调用此方法,可单个或批量发送。

获取未读彩信数量:

2、发送地址

相信本文所述实例对于大家的Android程序开发能起到一点参考借鉴作用。

3、发送参数

未接来电不能用 Observer监听,不过当有新的未接来电时,系统会发送一个广播com.android.phone.NotificationMgr.MissedCall_intent(锁屏上显示的未接来电数量就是通知监听这个广播实现的)

版权声明:本文由美高梅开户送58元官网发布于美高梅开户送58元官网,转载请注明出处:下面就以php语言为例为大家介绍下短信接口如何