<h2 style="box-sizing: inherit; -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-family: "Helvetica Neue", NotoSansHans-Regular, AvenirNext-Regular, arial, "Hiragino Sans GB", "Microsoft Yahei", "WenQuanYi Micro Hei", Arial, Helvetica, sans-serif; padding: 0px 0px 0.3em; font-weight: 400; line-height: 1.225; margin: 0px 0px 14px; font-size: 1.3em; border-bottom: 1px solid rgb(238, 238, 238); color: rgb(82, 82, 82); white-space: normal; background-color: rgb(255, 255, 255);">
<span style="box-sizing: inherit; -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-weight: bolder;">支付宝Oauth配置</span>
</h2>
<p style="box-sizing: inherit; -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; text-size-adjust: none; line-height: 2; margin-top: 0px; margin-bottom: 0px; padding: 0px; color: rgb(82, 82, 82); font-family: "Helvetica Neue", NotoSansHans-Regular, AvenirNext-Regular, arial, "Hiragino Sans GB", "Microsoft Yahei", "WenQuanYi Micro Hei", serif; font-size: 15px; white-space: normal; background-color: rgb(255, 255, 255);">
系统默认写好了Oauth方法 旧方法签名使用的RSA 但是现在新申请的应用签名使用RSA2
</p>
<p style="box-sizing: inherit; -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; text-size-adjust: none; line-height: 2; margin-top: 0px; margin-bottom: 0px; padding: 0px; color: rgb(82, 82, 82); font-family: "Helvetica Neue", NotoSansHans-Regular, AvenirNext-Regular, arial, "Hiragino Sans GB", "Microsoft Yahei", "WenQuanYi Micro Hei", serif; font-size: 15px; white-space: normal; background-color: rgb(255, 255, 255);">
<img src="https://box.kancloud.cn/579366df1a37cb3cc1cc8f0d2c62ded8_718x398.png" alt=""/>
</p>
<p style="box-sizing: inherit; -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; text-size-adjust: none; line-height: 2; margin-top: 0px; margin-bottom: 0px; padding: 0px; color: rgb(82, 82, 82); font-family: "Helvetica Neue", NotoSansHans-Regular, AvenirNext-Regular, arial, "Hiragino Sans GB", "Microsoft Yahei", "WenQuanYi Micro Hei", serif; font-size: 15px; white-space: normal; background-color: rgb(255, 255, 255);">
<span style="box-sizing: inherit; -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-weight: bolder;">如上图 如申请的应用有使用其他加密方式参数时可以使用默认的RSA签名(代码无需改动 使用下面的默认的公钥配置下就可以) 如没有则使用RSA2(修改代码 参考下面代码修改)</span>
</p>
<h3 style="box-sizing: inherit; -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-family: "Helvetica Neue", NotoSansHans-Regular, AvenirNext-Regular, arial, "Hiragino Sans GB", "Microsoft Yahei", "WenQuanYi Micro Hei", Arial, Helvetica, sans-serif; padding: 0px; font-weight: 400; line-height: 1.43; margin: 14px 0px; font-size: 1.2em; color: rgb(82, 82, 82); white-space: normal; background-color: rgb(255, 255, 255);">
<a style="box-sizing: inherit; -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; text-size-adjust: none; background-color: transparent; color: rgb(65, 131, 196); margin-top: -10px; position: absolute;"></a>申请应用步骤:
</h3>
<p style="box-sizing: inherit; -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; text-size-adjust: none; line-height: 2; margin-top: 0px; margin-bottom: 0px; padding: 0px; color: rgb(82, 82, 82); font-family: "Helvetica Neue", NotoSansHans-Regular, AvenirNext-Regular, arial, "Hiragino Sans GB", "Microsoft Yahei", "WenQuanYi Micro Hei", serif; font-size: 15px; white-space: normal; background-color: rgb(255, 255, 255);">
1.(企业或个人账户)登录https://open.alipay.com<br/>2.进入管理中心-头部菜单-开发者中心-网页&移动应用接入---创建应用选择-自定义接入-设置应用名称-创建<br/>3.创建完成后再功能列表添加功能-第三方应用授权-确定添加<br/>4.开发设置-加密方式处设置应用公钥(利用支付宝提供的生成工具生成就可以了,将生成的参数保存到公钥处)<br/>签名工具下载: <a href="https://docs.open.alipay.com/291/106097" target="_blank" style="box-sizing: inherit; -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; text-size-adjust: none; background-color: transparent; color: rgb(65, 131, 196); text-decoration-line: none;">https://docs.open.alipay.com/291/106097</a>
</p>
<h3 style="box-sizing: inherit; -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-family: "Helvetica Neue", NotoSansHans-Regular, AvenirNext-Regular, arial, "Hiragino Sans GB", "Microsoft Yahei", "WenQuanYi Micro Hei", Arial, Helvetica, sans-serif; padding: 0px; font-weight: 400; line-height: 1.43; margin: 14px 0px; font-size: 1.2em; color: rgb(82, 82, 82); white-space: normal; background-color: rgb(255, 255, 255);">
<a style="box-sizing: inherit; -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; text-size-adjust: none; background-color: transparent; color: rgb(65, 131, 196); margin-top: -10px; position: absolute;"></a>系统配置
</h3>
<p style="box-sizing: inherit; -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; text-size-adjust: none; line-height: 2; margin-top: 0px; margin-bottom: 0px; padding: 0px; color: rgb(82, 82, 82); font-family: "Helvetica Neue", NotoSansHans-Regular, AvenirNext-Regular, arial, "Hiragino Sans GB", "Microsoft Yahei", "WenQuanYi Micro Hei", serif; font-size: 15px; white-space: normal; background-color: rgb(255, 255, 255);">
品牌商总后台-系统配置-支付配置-支付宝Appid配置为上述申请应用后的Appid<br/>开发文件修改:<br/>根目录/ThinkPHP/Library/Vendor/alipay_sdk/AlipayAop.php<br/>方法为Alipay_oauth
</p>
<p style="box-sizing: inherit; -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; text-size-adjust: none; line-height: 2; margin-top: 0px; margin-bottom: 0px; padding: 0px; color: rgb(82, 82, 82); font-family: "Helvetica Neue", NotoSansHans-Regular, AvenirNext-Regular, arial, "Hiragino Sans GB", "Microsoft Yahei", "WenQuanYi Micro Hei", serif; font-size: 15px; white-space: normal; background-color: rgb(255, 255, 255);">
<span style="box-sizing: inherit; -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-weight: bolder;">默认代码为:</span>
</p>
<pre style="box-sizing: inherit; -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-family: Consolas, Monaco, "Andale Mono", "Ubuntu Mono", monospace; font-size: 15px; line-height: 1.45; margin-top: 14px; margin-bottom: 14px; padding: 16px; background-color: rgb(247, 247, 247); border: 0px; border-radius: 3px; overflow: auto; color: rgb(82, 82, 82);">public function Alipay_oauth($code,$app_id){
$aop = new AopClient();
$aop->appId = $app_id;
$aop->rsaPrivateKey = 'MIICXAIBAAKBgQCbX2YDb/1k/a0pK7GlMRzMV/HoePGrcfKr/WQoKDC26p9Jv3Y+qblO5Bqke9yJ234OM+cdOIU2WZMmJ2gQuI5FjyRLWJ/Sas09t2LCaOBBT88JO4EWtYBKfISUVPwyuROFf6SseXG7Xq72S58YR6P/QZ+oDFxqoSyep1REEf8zRQIDAQABAoGAed55OOcFvcpQoYN5QtZj/VBaGfuLq+uj6g3GGs1zcHZV3NXF3N7p0ByRXUUeNi+pD2DcvgnQS1I1Xm74bG0mgeYmc0pCu+lQ6nWusUmuAJVLOH5eLn7byunTsy1sMeNcNmrc3f/dY5Ez3UPT9ZRBAbOpjTNh52+7sJljoNEoWB0CQQDIgMTePhBHXIni0aP4rsgx0J3Nwtj6XYYCr87/rUv9sF4e11bVvoiaKDfYiIPmP0mcGRFRBtGWhGBBcadkWZh/AkEAxmDJCwCw7pzU9vVaS/Y9LPmOIHbT5453p8dy+3sjO2JjU+W3tAH8VnChUVeaK9Mv+8EUjabZMQxAbKq60E/yOwJAc5Vn6AY3NCwwgMUBlZaMacstbTRqCMppOptG5TVtnS1S1MymjklsThHpP7ZS8ySAtq/sv50CrZZaNt/h84OC2QJBAMFb/zm5P7wko7PfLFdUOQbIbA8ao6tVAy5HSrzypkGwwc4535gWQ2XhvGtzrrM+0stZxHXZhmO3ZGhG9XYsJpcCQEciKjeYTISSj0ocLvOxkaiJ2OgMdS6lcGJVi124Gk+zrICagTdJgL4Ujqca79lbPebXqbRuLdANg5qmU3tMa/Y=';
$aop->alipayrsaPublicKey = 'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCbX2YDb/1k/a0pK7GlMRzMV/HoePGrcfKr/WQoKDC26p9Jv3Y+qblO5Bqke9yJ234OM+cdOIU2WZMmJ2gQuI5FjyRLWJ/Sas09t2LCaOBBT88JO4EWtYBKfISUVPwyuROFf6SseXG7Xq72S58YR6P/QZ+oDFxqoSyep1REEf8zRQIDAQAB';
$aop->apiVersion = '1.0';
$aop->signType = 'RSA';
$aop->postCharset = 'UTF-8';
$aop->format = 'json';
$request = new AlipaySystemOauthTokenRequest();
$request->setGrantType("authorization_code");//设置要操作的类型
$request->setCode($code);
$response = $aop->execute($request);
$openid = $response->alipay_system_oauth_token_response->user_id;
return $openid;
}</pre>
<p style="box-sizing: inherit; -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; text-size-adjust: none; line-height: 2; margin-top: 0px; margin-bottom: 0px; padding: 0px; color: rgb(82, 82, 82); font-family: "Helvetica Neue", NotoSansHans-Regular, AvenirNext-Regular, arial, "Hiragino Sans GB", "Microsoft Yahei", "WenQuanYi Micro Hei", serif; font-size: 15px; white-space: normal; background-color: rgb(255, 255, 255);">
默认为RSA签名(如应用使用RSA方式则支付宝应用公钥设置为以下) 统一公钥为
</p>
<pre style="box-sizing: inherit; -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-family: Consolas, Monaco, "Andale Mono", "Ubuntu Mono", monospace; font-size: 15px; line-height: 1.45; margin-top: 14px; margin-bottom: 14px; padding: 16px; background-color: rgb(247, 247, 247); border: 0px; border-radius: 3px; overflow: auto; color: rgb(82, 82, 82);">MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCbX2YDb/1k/a0pK7GlMRzMV/HoePGrcfKr/WQoKDC26p9Jv3Y+qblO5Bqke9yJ234OM+cdOIU2WZMmJ2gQuI5FjyRLWJ/Sas09t2LCaOBBT88JO4EWtYBKfISUVPwyuROFf6SseXG7Xq72S58YR6P/QZ+oDFxqoSyep1REEf8zRQIDAQAB</pre>
<h3 style="box-sizing: inherit; -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-family: "Helvetica Neue", NotoSansHans-Regular, AvenirNext-Regular, arial, "Hiragino Sans GB", "Microsoft Yahei", "WenQuanYi Micro Hei", Arial, Helvetica, sans-serif; padding: 0px; font-weight: 400; line-height: 1.43; margin: 14px 0px; font-size: 1.2em; color: rgb(82, 82, 82); white-space: normal; background-color: rgb(255, 255, 255);">
<a style="box-sizing: inherit; -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; text-size-adjust: none; background-color: transparent; color: rgb(65, 131, 196); margin-top: -10px; position: absolute;"></a>使用RSA2方式(系统所有品牌都使用这个方式):
</h3>
<p style="box-sizing: inherit; -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; text-size-adjust: none; line-height: 2; margin-top: 0px; margin-bottom: 0px; padding: 0px; color: rgb(82, 82, 82); font-family: "Helvetica Neue", NotoSansHans-Regular, AvenirNext-Regular, arial, "Hiragino Sans GB", "Microsoft Yahei", "WenQuanYi Micro Hei", serif; font-size: 15px; white-space: normal; background-color: rgb(255, 255, 255);">
<img src="https://box.kancloud.cn/0a77e76a11ef650c959d4c90b6f9c04a_800x680.png" alt=""/><br/><span style="box-sizing: inherit; -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-weight: bolder;">如图中的公钥配置到支付宝应用中的公钥处</span>
</p>
<p style="box-sizing: inherit; -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; text-size-adjust: none; line-height: 2; margin-top: 0px; margin-bottom: 0px; padding: 0px; color: rgb(82, 82, 82); font-family: "Helvetica Neue", NotoSansHans-Regular, AvenirNext-Regular, arial, "Hiragino Sans GB", "Microsoft Yahei", "WenQuanYi Micro Hei", serif; font-size: 15px; white-space: normal; background-color: rgb(255, 255, 255);">
修改方法代码
</p>
<pre style="box-sizing: inherit; -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-family: Consolas, Monaco, "Andale Mono", "Ubuntu Mono", monospace; font-size: 15px; line-height: 1.45; margin-top: 14px; margin-bottom: 14px; padding: 16px; background-color: rgb(247, 247, 247); border: 0px; border-radius: 3px; overflow: auto; color: rgb(82, 82, 82);">$aop->rsaPrivateKey</pre>
<p style="box-sizing: inherit; -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; text-size-adjust: none; line-height: 2; margin-top: 0px; margin-bottom: 0px; padding: 0px; color: rgb(82, 82, 82); font-family: "Helvetica Neue", NotoSansHans-Regular, AvenirNext-Regular, arial, "Hiragino Sans GB", "Microsoft Yahei", "WenQuanYi Micro Hei", serif; font-size: 15px; white-space: normal; background-color: rgb(255, 255, 255);">
<span style="box-sizing: inherit; -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-weight: bolder;">参数改为生成的私钥参数</span>
</p>
<pre style="box-sizing: inherit; -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-family: Consolas, Monaco, "Andale Mono", "Ubuntu Mono", monospace; font-size: 15px; line-height: 1.45; margin-top: 14px; margin-bottom: 14px; padding: 16px; background-color: rgb(247, 247, 247); border: 0px; border-radius: 3px; overflow: auto; color: rgb(82, 82, 82);">$aop->alipayrsaPublicKey</pre>
<p style="box-sizing: inherit; -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; text-size-adjust: none; line-height: 2; margin-top: 0px; margin-bottom: 0px; padding: 0px; color: rgb(82, 82, 82); font-family: "Helvetica Neue", NotoSansHans-Regular, AvenirNext-Regular, arial, "Hiragino Sans GB", "Microsoft Yahei", "WenQuanYi Micro Hei", serif; font-size: 15px; white-space: normal; background-color: rgb(255, 255, 255);">
<span style="box-sizing: inherit; -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-weight: bolder;">参数改为生成的公钥参数</span>
</p>
<hr/>
<p style="box-sizing: inherit; -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; text-size-adjust: none; line-height: 2; margin-top: 0px; margin-bottom: 0px; padding: 0px; color: rgb(82, 82, 82); font-family: "Helvetica Neue", NotoSansHans-Regular, AvenirNext-Regular, arial, "Hiragino Sans GB", "Microsoft Yahei", "WenQuanYi Micro Hei", serif; font-size: 15px; white-space: normal; background-color: rgb(255, 255, 255);">
签名方式修改
</p>
<pre style="box-sizing: inherit; -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-family: Consolas, Monaco, "Andale Mono", "Ubuntu Mono", monospace; font-size: 15px; line-height: 1.45; margin-top: 14px; margin-bottom: 14px; padding: 16px; background-color: rgb(247, 247, 247); border: 0px; border-radius: 3px; overflow: auto; color: rgb(82, 82, 82);">$aop->signType = 'RSA';</pre>
<p style="box-sizing: inherit; -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; text-size-adjust: none; line-height: 2; margin-top: 0px; margin-bottom: 0px; padding: 0px; color: rgb(82, 82, 82); font-family: "Helvetica Neue", NotoSansHans-Regular, AvenirNext-Regular, arial, "Hiragino Sans GB", "Microsoft Yahei", "WenQuanYi Micro Hei", serif; font-size: 15px; white-space: normal; background-color: rgb(255, 255, 255);">
修改为:
</p>
<pre style="box-sizing: inherit; -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-family: Consolas, Monaco, "Andale Mono", "Ubuntu Mono", monospace; font-size: 15px; line-height: 1.45; margin-top: 14px; margin-bottom: 14px; padding: 16px; background-color: rgb(247, 247, 247); border: 0px; border-radius: 3px; overflow: auto; color: rgb(82, 82, 82);">$aop->signType = 'RSA2';</pre>
<p style="box-sizing: inherit; -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; text-size-adjust: none; line-height: 2; margin-top: 0px; margin-bottom: 0px; padding: 0px; color: rgb(82, 82, 82); font-family: "Helvetica Neue", NotoSansHans-Regular, AvenirNext-Regular, arial, "Hiragino Sans GB", "Microsoft Yahei", "WenQuanYi Micro Hei", serif; font-size: 15px; white-space: normal; background-color: rgb(255, 255, 255);">
如果系统多个品牌 多个appid使用的有RSA RSA2 两种方式
</p>
<p style="box-sizing: inherit; -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; text-size-adjust: none; line-height: 2; margin-top: 0px; margin-bottom: 0px; padding: 0px; color: rgb(82, 82, 82); font-family: "Helvetica Neue", NotoSansHans-Regular, AvenirNext-Regular, arial, "Hiragino Sans GB", "Microsoft Yahei", "WenQuanYi Micro Hei", serif; font-size: 15px; white-space: normal; background-color: rgb(255, 255, 255);">
那么需要修改代码来进行判断 用appid来判断 如下面示例
</p>
<pre style="box-sizing: inherit; -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-family: Consolas, Monaco, "Andale Mono", "Ubuntu Mono", monospace; font-size: 15px; line-height: 1.45; margin-top: 14px; margin-bottom: 14px; padding: 16px; background-color: rgb(247, 247, 247); border: 0px; border-radius: 3px; overflow: auto; color: rgb(82, 82, 82);"> public function Alipay_oauth($code,$app_id){
switch($appid){
case '2008xxxxxx':
$rsaPrivateKey='私钥';
$alipayrsaPublicKey='公钥';
$signType=‘RSA2’;//签名方式;
break;
......
default:
$rsaPrivateKey='私钥';
$alipayrsaPublicKey='公钥';
$signType=‘RSA’;//签名方式;
break;
}
$aop = new AopClient();
$aop->appId = $app_id;
$aop->rsaPrivateKey = $rsaPrivateKey;
$aop->alipayrsaPublicKey = $alipayrsaPublicKey;
$aop->apiVersion = '1.0';
$aop->signType = $signType;
$aop->postCharset = 'UTF-8';
$aop->format = 'json';
$request = new AlipaySystemOauthTokenRequest();
$request->setGrantType("authorization_code");//设置要操作的类型
$request->setCode($code);
$response = $aop->execute($request);
$openid = $response->alipay_system_oauth_token_response->user_id;
return $openid;
}</pre>
<p style="box-sizing: inherit; -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; text-size-adjust: none; line-height: 2; margin-top: 0px; margin-bottom: 0px; padding: 0px; color: rgb(82, 82, 82); font-family: "Helvetica Neue", NotoSansHans-Regular, AvenirNext-Regular, arial, "Hiragino Sans GB", "Microsoft Yahei", "WenQuanYi Micro Hei", serif; font-size: 15px; white-space: normal; background-color: rgb(255, 255, 255);">
<span style="box-sizing: inherit; -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; text-size-adjust: none; font-weight: bolder;">最重要的授权回调地址配置为自己的域名</span><br/><img src="https://box.kancloud.cn/95d7f54b82d6a0d08a447b30d07d9dea_743x447.png" alt=""/>
</p>
<p>
<br/>
</p>