vtiger crm6.0自定義短信服務商二次開發

可能有些人連配置都沒法新增 把vtigerCRM\modules\SMSNotifier\models 下的
Provide.php頁面的
if (!in_array($file, array('.', '..', 'MyProvider.php', 'CVS'))) {
改成
if (!in_array($file, array('.', '..', 'MyProvider.php', 'SMSProvider.php'))) {

然後進入 SMS供應商配置


vtiger crm6.0默認的是 Clickatell

Clickatell是一家加州的移動網關公司,他們的業務主要是B2C短信,比如幫助商家向客戶羣發折扣信息、廣告和其他通知短信等等。 我們國內一般不用這家公司的短信接口服務
都有自己的服務 


要加自己的配置 這裏最下面一句話有提到 https://wiki.vtiger.com/index.php/SMSNotifier_Module


Writing Custom Providers

If you have planning to use SMS service provider and don't find the connector to it, you will need to write one.
SMSNotifier module defines ISMSProvider (modules/SMSNotifier/ext/ISMSProvider.php) interface which should be implemented by your custom provider.
A template sample provide is available at: modules/SMSNotifier/ext/providers/MyProvider.php.sample
Also look at ClickATell provider implementation: modules/SMSNotifier/ext/providers/ClickATell.php

MyProvider.php.sample這個頁面時5.4的

6.0沒有
所以我們參考 ClickATell.php
把ClickATell.php這個頁面複製一份
改個名字  我這裏取名 qtsms.php
<?php


class SMSNotifier_qtsms_Provider implements SMSNotifier_ISMSProvider_Model {

	private $userName;
	private $password;
	private $parameters = array();

	const SERVICE_URI = '你的供應商url';
	private static $REQUIRED_PARAMETERS = array();   //具體根據你的短信接口加參數 我的短信接口就一個賬號密碼 還有一個寫死的參數所以這裏不需要了放空就行了
       
	/**
	 * Function to get provider name
	 * @return <String> provider name
	 */
	public function getName() {
		return 'qtsms';
	}

	/**
	 * Function to get required parameters other than (userName, password)
	 * @return <array> required parameters list
	 */
	public function getRequiredParams() {
		return self::$REQUIRED_PARAMETERS;
	}

	/**
	 * Function to get service URL to use for a given type
	 * @param <String> $type like SEND, PING, QUERY
	 */
	public function getServiceURL($type = false) {
		return self::SERVICE_URI;
	}

	/**
	 * Function to set authentication parameters
	 * @param <String> $userName
	 * @param <String> $password
	 */
	public function setAuthParameters($userName, $password) {
		$this->userName = $userName;
		$this->password = $password;
	}

	/**
	 * Function to set non-auth parameter.
	 * @param <String> $key
	 * @param <String> $value
	 */
	public function setParameter($key, $value) {
		$this->parameters[$key] = $value;
	}

	/**
	 * Function to get parameter value
	 * @param <String> $key
	 * @param <String> $defaultValue
	 * @return <String> value/$default value
	 */
	public function getParameter($key, $defaultValue = false) {
		if(isset($this->parameters[$key])) {
			return $this->parameters[$key];
		}
		return $defaultValue;
	}

	/**
	 * Function to prepare parameters
	 * @return <Array> parameters
	 */
	protected function prepareParameters() {
//主意 這裏的accout和pswd是我 自己公司短信接口的賬號和密碼參數  你們要根據自己的公司短信接口的賬號密碼參數來寫 這樣才能成功調用短信接口 

		return array('account' => $this->userName, 'pswd' => $this->password,'needstatus'=>'true');
		
	}

	/**
	 * Function to handle SMS Send operation
	 * @param <String> $message
	 * @param <Mixed> $toNumbers One or Array of numbers
	 */
	public function send($message, $toNumbers) {
		if(!is_array($toNumbers)) {
			$toNumbers = array($toNumbers);
		}

		$params = $this->prepareParameters();
		$params['msg'] = $message;  //這是我公司短信接口的信息參數名字 根據你具體短信接口 信息參數來寫
		$params['mobile'] = implode(',', $toNumbers);
//這是我公司短信接口的手機號碼參數名字 根據你具體短信接口 信息參數來寫


		$serviceURL = $this->getServiceURL();
		$httpClient = new Vtiger_Net_Client($serviceURL);
		$response = $httpClient->doPost($params);
		$responseLines = split("\n", $response);
		$result = array( 'error' => false, 'statusmessage' => '' );
		
		$res=split(',',$responseLines[0]);
        if($res[1]!=0){
			$result['error']=true;
			$result['statusmessage']='send failed';
			$result['to'] = 'no number';
		}else{
			$result['id'] = $responseLines[1];
			$result['to'] = $toNumbers;
			$result['status']='Processing';
		}

				
		return $result;
		
		
		
	}

	/**
	 * Function to get query for status using messgae id
	 * @param <Number> $messageId
	 */
	public function query($messageId) {
	//echo '12345';
		$params = $this->prepareParameters();
		$params['apimsgid'] = $messageId;

		$serviceURL = $this->getServiceURL(self::SERVICE_QUERY);
		$httpClient = new Vtiger_Net_Client($serviceURL);
		$response = $httpClient->doPost($params);
		$response = trim($response);

		$result = array( 'error' => false, 'needlookup' => 1, 'statusmessage' => '' );
	    //var_dump($response);exit;
	
		if($response==''){
					$result['error'] = true;
					$result['needlookup'] = 0;
					$result['statusmessage'] = '發送失敗';
		}
		
		return $result;
	}
}
?>


這個文件新增後 SMS供應商配置新增配置後 下拉框裏會多一個qtsms的選項
然後就填自己的參數值了


然後 在客戶列表那裏點擊 發送sms就可以羣發短信了
效果圖 :

230e9886-4cd9-32a4-9f8b-3c1f2be901cc.jpg

有什麼問題 加我qq 6637152交流


  • 230e9886-4cd9-32a4-9f8b-3c1f2be901cc-thumb.jpg
  • 大小: 24.2 KB
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章