php微信簽名 PHP微信介面簽名演算法

2021-10-22 21:30:07 字數 1359 閱讀 9981

一、引數說明

二、安全規範

1、簽名演算法

簽名生成的通用步驟如下:

第一步,設所有傳送或者接收到的資料為集合m,將集合m內非空引數值的引數按照引數名ascii碼從小到大排序(字典序),使用url鍵值對的格式(即key1=value1&key2=value2…)拼接成字串stringa。

特別注意以下重要規則:

◆ 引數名ascii碼從小到大排序(字典序);

◆ 如果引數的值為空不參與簽名;

◆ 引數名區分大小寫;

第二步,在stringa最後拼接上key得到stringsigntemp字串,並對stringsigntemp進行md5運算,再將得到的字串所有字元轉換為大寫,得到sign值signvalue。

舉例:mch_id: 10000100

device_info: 1000

body: test

nonce_str: ibuaivckdprxkhja

第二步:拼接api金鑰:stringsigntemp="stringa&key=192006250b4c09247ec02edce69f6a2d"

sign=md5(stringsigntemp).touppercase()="9a0a8659f005d6984697e2ca0a9cf3b7"

最終得到最終傳送的資料:

wxd930ea5d5a258f4f

ibuaivckdprxkhja

9a0a8659f005d6984697e2ca0a9cf3b7

2、生成隨機數演算法

function randomkeys($length) ;

return $returnstr;

}//簽名演算法

function makesignature($args,$key)

ksort($args);

$stringa = '';

$stringsigntemp = '';

foreach($args as $k => $v) {

$stringa .= $k . '=' . $v . '&';

$stringsigntemp = $stringa.'key='.$key;

$signature = strtoupper(md5($stringsigntemp));

$newstring = $stringa.'signature='.$signature;

$newsign = base64_encode($newstring);

return $newsign;

點讚 (0)賞分享 (0)

php微信生成簽名 php 微信支付簽名快速生成

陣列轉xml可以封裝到common中,重要 以下2行 排序 ksort post 生成sign 全部 統一下單介面 public function unifiedorder wechat this wechat model getactive 從配置檔案或資料庫獲取資訊 post array pos...

php微信生成簽名 php 微信支付簽名快速生成

陣列轉xml可以封裝到common中,重要 以下2行 排序 ksort post 生成sign 全部 統一下單介面 public function unifiedorder wechat this wechat model getactive 從配置檔案或資料庫獲取資訊 post array pos...

PHP 微信介面封裝

created by phpstorm.user e450 date 2017 12 5 time 10 36 namespace usecouchbase exception usethink facade log useuse usethink facade cookie class wecha...