联系官方销售客服
1835022288
028-61286886
短信接口自己胡改八改的倒是生效了(改成了面向过程的,没有类,只有函数)
普通的注册啥的都没问题,但是发现在订单通知时出现redeclare(或类似重复声明)错误。
查看订单通知\diy\module\order\models\Order_model.php的notice函数才知道,是通知买家、卖家双方,代码如下:
// 通知买家
if ($buy) {
$this->member_model->sendsms($order['shipping_phone'], $content);
}
// 通知商家
if ($sell) {
$m = dr_member_info($sell);
if ($m['phone']) {
$this->member_model->sendsms($m['phone'], $content);
}
}
因为面向过程,这样一来,我在的sendsms() 这个函数里的子函数就在一个被重复声明两次,请问高手,这个怎么破?
附\diy\module\member\models\Member_model.php的sendsms函数代码如下:
/**
* 短信发送
*
* @param string $mobile
* @param string $content
* @return bool
*/
public function sendsms($mobile, $content) {
if (!$mobile || !$content) {
return FALSE;
}
function req($accessKeyId, $accessKeySecret, $domain, $params)
{
$apiParams = array_merge(array (
"SignatureMethod" => "HMAC-SHA1",
"SignatureNonce" => uniqid(mt_rand(0,0xffff), true),
"SignatureVersion" => "1.0",
"AccessKeyId" => $accessKeyId,
"Timestamp" => gmdate("Y-m-d\TH:i:s\Z"),
"Format" => "JSON",
), $params);
ksort($apiParams);
$sortedQueryStringTmp = "";
foreach ($apiParams as $key => $value) {
$sortedQueryStringTmp .= "&" . encode($key) . "=" . encode($value);
}
$stringToSign = "GET&%2F&" . encode(substr($sortedQueryStringTmp, 1));
$sign = base64_encode(hash_hmac("sha1", $stringToSign, $accessKeySecret . "&",true));
$signature = encode($sign);
$url = "http://{$domain}/?Signature={$signature}{$sortedQueryStringTmp}";
try {
$content = fetchContent($url);
return json_decode($content);
} catch( \Exception $e) {
return false;
}
}
function encode($str)
{
$res = urlencode($str);
$res = preg_replace("/\+/", "%20", $res);
$res = preg_replace("/\*/", "%2A", $res);
$res = preg_replace("/%7E/", "~", $res);
return $res;
}
function fetchContent($url) {
if(function_exists("curl_init")) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"x-sdk-client" => "php/2.0.0"
));
$rtn = curl_exec($ch);
if($rtn === false) {
trigger_error("[CURL_" . curl_errno($ch) . "]: " . curl_error($ch), E_USER_ERROR);
}
curl_close($ch);
return $rtn;
}
$context = stream_context_create(array(
"http" => array(
"method" => "GET",
"header" => array("x-sdk-client: php/2.0.0"),
)
));
return file_get_contents($url, false, $context);
}
$params = array ();
$accessKeyId = "阿里云短信id";
$accessKeySecret = "阿里云短信secret";
$params["PhoneNumbers"] = $mobile;//$phone;
$params["SignName"] = "阿里云短信模板签名";
$params["TemplateCode"] = "SMS_109465355";
$params['TemplateParam'] = Array (
"code" => $content,
"product" => "阿里通信"
);
// fixme 可选: 设置发送短信流水号
$params['OutId'] = "12345";
$params['SmsUpExtendCode'] = "1234567";
// *** 需用户填写部分结束, 以下代码若无必要无需更改 ***
if(!empty($params["TemplateParam"]) && is_array($params["TemplateParam"])) {
$params["TemplateParam"] = json_encode($params["TemplateParam"]);
}
// 初始化SignatureHelper实例用于设置参数,签名以及发送请求
// 此处可能会抛出异常,注意catch
$content1 = req(
$accessKeyId,
$accessKeySecret,
"dysmsapi.aliyuncs.com",
array_merge($params, array(
"RegionId" => "cn-hangzhou",
"Action" => "SendSms",
"Version" => "2017-05-25",
))
);
$result=dr_object2array($content1);
//$myfile = fopen("newfile9.txt", "w") or die("Unable to open file!");
//fwrite($myfile, dr_array2string(result['Code']));
//fclose($myfile);
/*
$file = WEBPATH.'config/sms.php';
if (!is_file($file)) {
return FALSE;
}
$config = require_once $file;
if ($config['third']) {
$this->load->helper('sms');
if (function_exists('my_sms_send')) {
//$result = my_sms_send($mobile, $content, $config);
} else {
return FALSE;
}
} /*else {
$result = dr_catcher_data('http://sms.xunruicms.com/index.php?uid='.$config['uid'].'&key='.$config['key'].'&mobile='.$mobile.'&content='.$content.'【'.$config['note'].'】&domain='.trim(str_replace('http://', '', SITE_URL), '/').'&sitename='.SITE_NAME);
if (!$result) {
return FALSE;
}
$result = json_decode($result, true);
}*/
if ($result['Code']=='OK') {
return array('status' => 1, 'msg' => '发送成功');
} else {
return array('status' => 0, 'msg' => '短信通道:'.$result['Message']);
}
}
谁来帮姐啊