多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
人人商城小程序配置 ``` module.exports\={     appid:"wx05dd69862a06aa03",//修改小程序appid     api:"https://test.test.cn/app/ewei\_shopv2\_api.php?i=1",//修改后台域名和公众号unaicd i 参数看微擎后台哪个公众号他的数字是几就是几     approot:"https://test.test.cn/addons/ewei\_shopv2/",//修改后台域名     userInfo:null }; ``` ![](https://img.kancloud.cn/98/f6/98f6e2e0f9dadc864f30e5ae1e5aa108_1878x942.png) 小程序接口访问地址 ``` http://wq.cn/app/ewei_shopv2_api.php?i=1&r= r参数 就是 app 下面文件夹 用.“.”来连接就行 ``` 人人商城php7环境 小程序加解密 ![](https://img.kancloud.cn/9d/8e/9d8ed6676ef7f6bbab0e607ce8fc761e_588x287.png) wxBizDataCrypt.php: ``` ~~~ <?php require_once EWEI_SHOPV2_PLUGIN . "app/core/wxapp/pkcs7Encoder.php"; /** * 对微信小程序用户加密数据的解密示例代码. * * @copyright Copyright (c) 1998-2014 Tencent Inc. */ class WXBizDataCrypt { private $appid = NULL; private $sessionKey = NULL; /** * 构造函数 * @param $sessionKey string 用户在小程序登录后获取的会话密钥 * @param $appid string 小程序的appid */ public function WXBizDataCrypt($appid, $sessionKey) { $this->sessionKey = $sessionKey; $this->appid = $appid; } /** * 检验数据的真实性,并且获取解密后的明文.php7.0以下 * @param $encryptedData string 加密的用户数据 * @param $iv string 与用户数据一同返回的初始向量 * @param $data string 解密后的原文 * * @return int 成功0,失败返回对应的错误码 */ // public function decryptData($encryptedData, $iv, &$data) // { // if (strlen($this->sessionKey) != 24) { // return ErrorCode::$IllegalAesKey; // } // $aesKey = base64_decode($this->sessionKey); // if (strlen($iv) != 24) { // return ErrorCode::$IllegalIv; // } // $aesIV = base64_decode($iv); // $aesCipher = base64_decode($encryptedData); // $pc = new Prpcrypt($aesKey); // $result = $pc->decrypt($aesCipher, $aesIV); // if ($result[0] != 0) { // return $result[0]; // } // $dataObj = json_decode($result[1]); // if ($dataObj == NULL) { // return ErrorCode::$IllegalBuffer; // } // if ($dataObj->watermark->appid != $this->appid) { // return ErrorCode::$IllegalBuffer; // } // $data = $result[1]; // return ErrorCode::$OK; // } public function decryptData( $encryptedData, $iv, &$data ) { if (strlen($this->sessionKey) != 24) { return ErrorCode::$IllegalAesKey; } $aesKey=base64_decode($this->sessionKey); if (strlen($iv) != 24) { return ErrorCode::$IllegalIv; } $aesIV=base64_decode($iv); //$aesCipher=base64_decode($encryptedData); $aesCipher=$encryptedData; $pc = new Prpcrypt($aesKey); $result = $pc->decrypt($aesCipher,$aesIV); if ($result[0] != 0) { return $result[0]; } $dataObj=json_decode( $result[1] ); if( $dataObj == NULL ) { return ErrorCode::$IllegalBuffer.'--'; } if( $dataObj->watermark->appid != $this->appid ) { return ErrorCode::$IllegalBuffer.';;'; } $data = $result[1]; return ErrorCode::$OK; } } ?> ``` pkcs7Encoder.php ___ ``` <?php require_once EWEI_SHOPV2_PLUGIN . "app/core/wxapp/errorCode.php"; /** * PKCS7Encoder class * * 提供基于PKCS7算法的加解密接口. */ class PKCS7Encoder { public static $block_size = 16; /** * 对需要加密的明文进行填充补位 * @param $text 需要进行填充补位操作的明文 * @return 补齐明文字符串 */ public function encode($text) { $block_size = PKCS7Encoder::$block_size; $text_length = strlen($text); $amount_to_pad = PKCS7Encoder::$block_size - $text_length % PKCS7Encoder::$block_size; if ($amount_to_pad == 0) { $amount_to_pad = PKCS7Encoder::block_size; } $pad_chr = chr($amount_to_pad); $tmp = ""; for ($index = 0; $index < $amount_to_pad; $index++) { $tmp .= $pad_chr; } return $text . $tmp; } /** * 对解密后的明文进行补位删除 * @param decrypted 解密后的明文 * @return 删除填充补位后的明文 */ public function decode($text) { $pad = ord(substr($text, -1)); if ($pad < 1 || 32 < $pad) { $pad = 0; } return substr($text, 0, strlen($text) - $pad); } } /** * Prpcrypt class * * */ class Prpcrypt { public $key = NULL; public function Prpcrypt($k) { $this->key = $k; } /** * 对密文进行解密 php7.0以下 * @param string $aesCipher 需要解密的密文 * @param string $aesIV 解密的初始向量 * @return string 解密得到的明文 */ /* public function decrypt($aesCipher, $aesIV) { try { $module = mcrypt_module_open(MCRYPT_RIJNDAEL_128, "", MCRYPT_MODE_CBC, ""); exit('4545454'); mcrypt_generic_init($module, $this->key, $aesIV); $decrypted = mdecrypt_generic($module, $aesCipher); mcrypt_generic_deinit($module); mcrypt_module_close($module); } catch (Exception $e) { return array(ErrorCode::$IllegalBuffer, NULL); } try { $pkc_encoder = new PKCS7Encoder(); $result = $pkc_encoder->decode($decrypted); } catch (Exception $e) { return array(ErrorCode::$IllegalBuffer, NULL); } return array(0, $result); }*/ public function decrypt( $aesCipher, $aesIV ) { try { $decrypted = openssl_decrypt($aesCipher,'AES-128-CBC',$this->key,OPENSSL_ZERO_PADDING,$aesIV); // var_dump($decrypted); } catch (Exception $e) { return array(ErrorCode::$IllegalBuffer, null); } try { //去除补位字符 $pkc_encoder = new PKCS7Encoder; $result = $pkc_encoder->decode($decrypted); } catch (Exception $e) { //print $e; return array(ErrorCode::$IllegalBuffer, null); } return array(0, $result); } } ?> ``` 微擎直接跳转到人人商城首页 > $forward='xxxxx'; ![](https://img.kancloud.cn/16/8b/168b28fbc002a903ce1e1099f2c64bed_1487x549.png)