wemall-mobile is an Android app mall based on WeMall. You only need to upload the interface file in the original mall directory to complete the server-side configuration. The client can be customized and modified. This article shares the Alipay interface public functions of the wemall app mall source code Android. This class is the core processing file of the public functions called by the request and notification return files for technicians to refer to and learn.
The following code is only a sample code provided to facilitate merchant testing. Merchants can write it according to the technical documentation according to the needs of their own websites. It is not necessary to use this code. This code is only for learning and researching the Alipay interface and is only provided as a reference.
Concatenate all the elements of the array into a string using the "&" character according to the pattern of "parameter = parameter value"
wemall官网地址:http://www.wemallshop.com
function createLinkstring($para) {
$arg = "";
While (list ($key, $val) = each ($para)) {
$arg.=$key."=".$val."&";
}
//Remove the last & character
$arg = substr($arg,0,count($arg)-2);
//If there is an escape character, remove the escape
If(get_magic_quotes_gpc()){$arg = stripslashes($arg);}
Return $arg;
}
/**
* Concatenate all the elements of the array into a string using the "&" character according to the pattern of "parameter = parameter value", and perform urlencode encoding on the string
* @param $para Array to be spliced
* return the string after the splicing is completed
*/
function createLinkstringUrlencode($para) {
$arg = "";
While (list ($key, $val) = each ($para)) {
$arg.=$key."=".urlencode($val)."&";
}
//Remove the last & character
$arg = substr($arg,0,count($arg)-2);
//If there is an escape character, remove the escape
If(get_magic_quotes_gpc()){$arg = stripslashes($arg);}
Return $arg;
}
/**
* Remove null values and signature parameters in the array
* @param $para Signature parameter group
* return The new signature parameter group after removing the null value and signature parameters
*/
function paraFilter($para) {
$para_filter = array();
While (list ($key, $val) = each ($para)) {
If($key == "sign" || $key == "sign_type" || $val == "")continue;
Else $ Para_filter [$ key] = $ Para [$ key];
}
Return $para_filter;
}
/**
* Sort the array
* @param $para Array before sorting
* return sorted array
*/
function argSort($para) {
ksort($para);
reset($para);
Return $para;
}
/**
* Write logs to facilitate testing (depending on the website requirements, you can also change the records to be stored in the database)
* Note: The server needs to enable fopen configuration
* @param $word The text content to be written in the log Default value: null
*/
function logResult($word='') {
$fp = fopen("log.txt","a");
flock($fp, LOCK_EX) ;
fwrite($fp,"Execution date:".strftime("%Y%m%d%H%M%S",time())."n".$word."n");
flock($fp, LOCK_UN);
fclose($fp);
}
/**
* Remotely obtain data, POST mode
* Note:
* 1. To use Crul, you need to modify the settings of the php.ini file in the server. Find php_curl.dll and remove the ";" in front of it
* 2. cacert.pem in the folder is an SSL certificate. Please ensure that its path is valid. The current default path is: getcwd().'\cacert.pem'
* @param $url specifies the full path address of the URL
* @param $cacert_url specifies the absolute path of the current working directory
* @param $para Requested data
* @param $input_charset encoding format. Default value: null
* return remote output data
*/
function getHttpResponsePOST($url, $cacert_url, $para, $input_charset = '') {
If (trim($input_charset) != '') {
$url = $url."_input_charset=".$input_charset;
}
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true);//SSL certificate authentication
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2);//Strict authentication
curl_setopt($curl, CURLOPT_CAINFO,$cacert_url);//Certificate address
curl_setopt($curl, CURLOPT_HEADER, 0); // Filter HTTP header
curl_setopt($curl,CURLOPT_RETURNTRANSFER, 1); // Display the output results
curl_setopt($curl,CURLOPT_POST,true); // post transfer data
curl_setopt($curl,CURLOPT_POSTFIELDS,$para); // post transfer data
$responseText = curl_exec($curl);
//var_dump( curl_error($curl) );//If an exception occurs during curl execution, you can turn on this switch to view the exception content
curl_close($curl);
Return $responseText;
}
/**
* Remotely obtain data, GET mode
* Note:
* 1. To use Crul, you need to modify the settings of the php.ini file in the server. Find php_curl.dll and remove the ";" in front of it
* 2. cacert.pem in the folder is an SSL certificate. Please ensure that its path is valid. The current default path is: getcwd().'\cacert.pem'
* @param $url specifies the full path address of the URL
* @param $cacert_url specifies the absolute path of the current working directory
* return remote output data
*/
function getHttpResponseGET($url,$cacert_url) {
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_HEADER, 0); // Filter HTTP header
curl_setopt($curl,CURLOPT_RETURNTRANSFER, 1); // Display the output results
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true);//SSL certificate authentication
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2);//Strict authentication
curl_setopt($curl, CURLOPT_CAINFO,$cacert_url);//Certificate address
$responseText = curl_exec($curl);
//var_dump( curl_error($curl) );//If an exception occurs during curl execution, you can turn on this switch to view the exception content
curl_close($curl);
Return $responseText;
}
/**
* Implement multiple character encoding methods
* @param $input The string that needs to be encoded
* @param $_output_charset Output encoding format
* @param $_input_charset Input encoding format
* return the encoded string
*/
function charsetEncode($input,$_output_charset,$_input_charset) {
$output = "";
If(!isset($_output_charset) )$_output_charset = $_input_charset;
If($_input_charset == $_output_charset || $input ==null ) {
$output = $input;
} elseif (function_exists("mb_convert_encoding")) {
$output = mb_convert_encoding($input,$_output_charset,$_input_charset);
} elseif(function_exists("iconv")) {
$output = iconv($_input_charset,$_output_charset,$input);
else die("sorry, you have no libs support for charset change.");
Return $output;
}
/**
* Implement multiple character decoding methods
* @param $input The string to be decoded
* @param $_output_charset Output decoding format
* @param $_input_charset 输入的解码格式
* return 解码后的字符串
*/
function charsetDecode($input,$_input_charset ,$_output_charset) {
$output = "";
if(!isset($_input_charset) )$_input_charset = $_input_charset ;
if($_input_charset == $_output_charset || $input ==null ) {
$output = $input;
} elseif (function_exists("mb_convert_encoding")) {
$output = mb_convert_encoding($input,$_output_charset,$_input_charset);
} elseif(function_exists("iconv")) {
$output = iconv($_input_charset,$_output_charset,$input);
} else die("sorry, you have no libs support for charset changes.");
return $output;
}
?>