例1,将短信发送写成一个函数。
将函数定义在Function.php中,例如:
//php短信发送函数
//by www.
function smsto($telphone,$message)
{
//短信接口用户名 $uid,
$uid = 'qxt01';
//短信接口密码 $passwd
$passwd = '123456';
//发送到的目标手机号码 $telphone
//$telphone = '139xxxxxxx';//此处改成自己的手机号
//短信内容 $message
//$message = "这是一条测试信息";
$message1 =urlencode(mb_convert_encoding($message, 'utf-8', 'gb2312'));
$gateway = "http://www./msgsend.ashx?USERNAME={$uid}&PASSWORD={$passwd}&MOBILE={$telphone}&CONTENT={$message1}&SEQ=1000";
$result = file_get_contents($gateway);
return $result;
}
调用示例:
$SendMember = $_POST["SendMember"]; //说明:取用户输入的手号,也可以自己指定手机号
$SendMSG = $_POST["SendMSG"];//说明:取用户输入的短信内容,也可以自己指定内容
$smsok=smsto($SendMember,$SendMSG);
返回1说明成功,更多返回值请查看接口说明。
猜你喜欢:php 短信接口的示例代码(入门)
例2,
第一步:先到www.woxp.cn注册一个会员账号;
第二步:在test.php文件中插入代码:
$cont="你好,这是一条测试短信!";
$mynum="手机号码";
$url='http://gateway.woxp.cn:6630/gb2312/web_api/?x_eid=0&x_uid=会员账号&x_pwd_md5=MD5加密后的密码&x_ac=10&x_target_no='."$mynum".'&x_memo='."$cont".'&x_gate_id=300';
echo Get($url);
function Get($url){
if(function_exists('file_get_contents')){
$file_contents = file_get_contents($url);
}else{
$ch = curl_init();
$timeout = 5;
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$file_contents = curl_exec($ch);
curl_close($ch);
}
return $file_contents;
}
?>
第三步,浏览test.php,参数配置正确的话,短信即可成功到达预设手机号码上了。
在php中的任何类,它包含一个或多个抽象方法时,则必须声明为抽象类。
抽象类不能实例化。
一个类,如果它扩展了抽象类,则必须实现父类的抽象方法。
例子:
<?
/**
* php抽象类与抽象方法的例子
* edit: www.
*/
abstract class Animal{
function __construct($name='No-name', $breed='unknown', $price = 15) {
$this->name = $name;
$this->breed = $breed;
$this->price = $price;
}
function setName($name) {
$this->name = $name;
}
function setBreed($breed){
$this->breed = $breed;
}
function setPrice($price) {
$this->price = $price < 0 ? 0 : $price;
}
function getName() {
return $this->name;
}
function display() {
printf("<p>%s is a %s and costs \$%.2f.</p>\n", $this->name, $this->breed, $this->price);
}
public static $type = "animal";
public static function fly($direction = 'around') {
printf("<p>Flying %s.</p>\n", $direction);
}
abstract public function birdCall();
}
class Parrot extends Animal {
public function birdCall($singing=FALSE) {
$sound = $singing ? "twitter" : "chirp";
printf("<p>%s says: *%s*</p>\n", $this->getName(), $sound);
}
}
?>
例1,php抽象类
<?php
//定义一个抽象类
abstract class Staff
{
abstract function hire();
abstract function fire();
abstract function promote();
abstract function demote();
}
?>
例2,php抽象类的例子
<?php
class Employee {
private $title;
private $lastName;
private $firstName;
protected $salary;
private $ratio = 0;
public function __construct($title, $firstName, $mainName, $salary ) {
$this->title = $title;
$this->firstName = $firstName;
$this->lastName = $mainName;
$this->salary = $salary;
}
public function firstName() {
return $this->firstName;
}
public function getlastName() {
return $this->lastName;
}
public function setRatio( $num ) {
$this->ratio=$num;
}
public function getRatio() {
return $this->ratio;
}
public function getTitle() {
return $this->title;
}
public function getSalary() {
return ($this->salary - $this->ratio);
}
public function getFullName() {
return "{$this->firstName}" . " {$this->lastName}";
}
function getSummaryLine() {
$base = "$this->title ( $this->lastName, ";
$base .= "$this->firstName )";
return $base;
}
}
//定义抽象类
abstract class EmployeeWriter {
abstract static function write( Employee $shopProduct );
}
class TextEmployeeWriter extends EmployeeWriter {
static function write( Employee $shopEmployee ) {
$str = "{$shopEmployee->getTitle()}: ";
$str .= $shopEmployee->getFullName();
$str .= " ({$shopEmployee->getSalary()})\n";
print $str;
}
}
$developer1 = new Employee("A", "A1", "A2", 5.99 );
TextEmployeeWriter::write( $developer1 );
?>