移动端微信接入
This commit is contained in:
parent
ca91f45ef3
commit
31e8e3bebb
92
Assets/Editor/XCodePostProcessBuild.cs
Normal file
92
Assets/Editor/XCodePostProcessBuild.cs
Normal file
@ -0,0 +1,92 @@
|
||||
|
||||
using UnityEditor;
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
|
||||
#if UNITY_IOS && UNITY_EDITOR
|
||||
using UnityEditor.Callbacks;
|
||||
using UnityEditor.iOS.Xcode;
|
||||
#endif
|
||||
|
||||
public static class XCodePostProcessBuild
|
||||
{
|
||||
#if UNITY_IOS && UNITY_EDITOR
|
||||
private static readonly string[] csAddFrameworks = new string[]{
|
||||
"Security.framework","WebKit.framework", "CoreGraphics.framework"
|
||||
};
|
||||
|
||||
[PostProcessBuild(1)]
|
||||
public static void OnPostprocessBuild(BuildTarget buildTarget, string pathToBuiltProject)
|
||||
{
|
||||
if (BuildTarget.iOS != buildTarget)
|
||||
{
|
||||
return;
|
||||
}
|
||||
string projectPath = pathToBuiltProject + "/Unity-iPhone.xcodeproj/project.pbxproj";
|
||||
SetFrameworksAndBuildSettings(projectPath);
|
||||
SetInfoList(pathToBuiltProject, "com.ZhiXingPai.PowerFun", "wx9146e6697a6aef2d");
|
||||
SetAssociatedDomains(projectPath, "wx.powerfun.com.cn");
|
||||
}
|
||||
|
||||
private static void SetFrameworksAndBuildSettings(string path)
|
||||
{
|
||||
PBXProject proj = new PBXProject();
|
||||
proj.ReadFromString(File.ReadAllText(path));
|
||||
string target = proj.GetUnityMainTargetGuid();
|
||||
Debug.Log("Target Name is " + target);
|
||||
// 设置 BuildSettings
|
||||
proj.AddBuildProperty(target, "Other Linker Flags", "-Objc -all_load");
|
||||
proj.SetBuildProperty(target, "ENABLE_BITCODE", "NO");
|
||||
|
||||
//根据微信SDK文档的要求,加入相关的Frameworks
|
||||
for (int i = 0; i < csAddFrameworks.Length; ++i)
|
||||
{
|
||||
if (!proj.ContainsFramework(target, csAddFrameworks[i]))
|
||||
proj.AddFrameworkToProject(target, csAddFrameworks[i], false);
|
||||
}
|
||||
|
||||
File.WriteAllText(path, proj.WriteToString());
|
||||
}
|
||||
|
||||
public static void SetInfoList(string buildPath, string wxUrlName, string wxScheme)
|
||||
{
|
||||
string listPath = buildPath + "/Info.plist";
|
||||
PlistDocument plist = new PlistDocument();
|
||||
plist.ReadFromString(File.ReadAllText(listPath));
|
||||
|
||||
// 在“info”标签栏的“URL type“添加“URL scheme”,值为你在微信后台注册的应用程序的 AppID
|
||||
PlistElementArray urlArray = plist.root.CreateArray("CFBundleURLTypes");
|
||||
PlistElementDict dict = urlArray.AddDict();
|
||||
dict.SetString("CFBundleTypeRole", "Editor");
|
||||
dict.SetString("CFBundleURLName", wxUrlName);
|
||||
PlistElementArray urlSchemes = dict.CreateArray("CFBundleURLSchemes");
|
||||
urlSchemes.AddString(wxScheme);
|
||||
|
||||
// 在 “info”标签栏的“LSApplicationQueriesSchemes“添加weixin wechat和weixinULAPI
|
||||
PlistElementArray wxArray = plist.root.CreateArray("LSApplicationQueriesSchemes");
|
||||
wxArray.AddString("weixin");
|
||||
wxArray.AddString("wechat");
|
||||
wxArray.AddString("weixinULAPI");
|
||||
|
||||
PlistElementDict qxLoc = plist.root.CreateDict("NSLocationWhenInUseUsageDescription");
|
||||
qxLoc.SetBoolean("NSLocationWhenInUseUsageDescription", true);
|
||||
|
||||
File.WriteAllText(listPath, plist.WriteToString());
|
||||
}
|
||||
|
||||
// 设置Associated Domains
|
||||
public static void SetAssociatedDomains(string pbxProjectPath, string domainUrl)
|
||||
{
|
||||
//默认 Target Name, 你自己的可能不一样
|
||||
string targetName = "Unity-iPhone";
|
||||
//Set the entitlements file name to what you want but make sure it has this extension
|
||||
string entitlementsFileName = "my_app.entitlements";
|
||||
|
||||
var entitlements = new ProjectCapabilityManager(pbxProjectPath, entitlementsFileName, targetName);
|
||||
entitlements.AddAssociatedDomains(new string[] { "applinks:" + domainUrl });
|
||||
|
||||
entitlements.WriteToFile();
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
11
Assets/Editor/XCodePostProcessBuild.cs.meta
Normal file
11
Assets/Editor/XCodePostProcessBuild.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 84ef3790c38d9564cb7770687283c42d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
BIN
Assets/Plugins/Android/UnityCallWechatShare-release.aar
Normal file
BIN
Assets/Plugins/Android/UnityCallWechatShare-release.aar
Normal file
Binary file not shown.
32
Assets/Plugins/Android/UnityCallWechatShare-release.aar.meta
Normal file
32
Assets/Plugins/Android/UnityCallWechatShare-release.aar.meta
Normal file
@ -0,0 +1,32 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 53d84661e0b3c5349a17e6043175d0d9
|
||||
PluginImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
iconMap: {}
|
||||
executionOrder: {}
|
||||
defineConstraints: []
|
||||
isPreloaded: 0
|
||||
isOverridable: 0
|
||||
isExplicitlyReferenced: 0
|
||||
validateReferences: 1
|
||||
platformData:
|
||||
- first:
|
||||
Android: Android
|
||||
second:
|
||||
enabled: 1
|
||||
settings: {}
|
||||
- first:
|
||||
Any:
|
||||
second:
|
||||
enabled: 0
|
||||
settings: {}
|
||||
- first:
|
||||
Editor: Editor
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
DefaultValueInitialized: true
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
BIN
Assets/Plugins/Android/powerfun.keystore
Normal file
BIN
Assets/Plugins/Android/powerfun.keystore
Normal file
Binary file not shown.
7
Assets/Plugins/Android/powerfun.keystore.meta
Normal file
7
Assets/Plugins/Android/powerfun.keystore.meta
Normal file
@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 306a0c395439baa468b3bcd3fe5983ae
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/Plugins/iOS.meta
Normal file
8
Assets/Plugins/iOS.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7cce98d172bfd2f4fa235200a8c37ffd
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
69
Assets/Plugins/iOS/IOSWechatController.m
Normal file
69
Assets/Plugins/iOS/IOSWechatController.m
Normal file
@ -0,0 +1,69 @@
|
||||
//
|
||||
// IOSWechatController.m
|
||||
// Unity-iPhone
|
||||
//
|
||||
// Created by Jooki Tsui on 2020/11/13.
|
||||
//
|
||||
|
||||
#import "WXApi.h"
|
||||
#import "UnityAppController.h"
|
||||
#import <Foundation/Foundation.h>
|
||||
extern void UnitySendMessage(const char *,const char *,const char *);
|
||||
@interface IOSWechatController : UnityAppController<WXApiDelegate>
|
||||
@end
|
||||
|
||||
IMPL_APP_CONTROLLER_SUBCLASS (IOSWechatController)
|
||||
|
||||
@implementation IOSWechatController
|
||||
|
||||
- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity
|
||||
#if defined(__IPHONE_12_0) || defined(__TVOS_12_0)
|
||||
restorationHandler:(void (^)(NSArray<id<UIUserActivityRestoring> > * _Nullable restorableObjects))restorationHandler
|
||||
#else
|
||||
restorationHandler:(void (^)(NSArray * _Nullable))restorationHandler
|
||||
#endif
|
||||
{
|
||||
return [WXApi handleOpenUniversalLink:userActivity delegate:self];
|
||||
}
|
||||
|
||||
- (BOOL)application:(UIApplication*)application openURL:(NSURL*)url
|
||||
options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options
|
||||
{
|
||||
return [WXApi handleOpenURL:url delegate:self];
|
||||
}
|
||||
|
||||
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
|
||||
{
|
||||
return [WXApi handleOpenURL:url delegate:self];
|
||||
}
|
||||
|
||||
- (void)onResp:(BaseResp *)resp
|
||||
{
|
||||
NSLog(@"47");
|
||||
if([resp isKindOfClass:[SendAuthResp class]])
|
||||
{
|
||||
SendAuthResp *temp = (SendAuthResp*)resp;
|
||||
int errorCode = temp.errCode;
|
||||
switch (errorCode) {
|
||||
case 0:
|
||||
UnitySendMessage("LoginPanel", "OnMobileWxLoginResp",[NSString stringWithFormat:@"true;%@",temp.code ].UTF8String);
|
||||
break;
|
||||
case -2:
|
||||
UnitySendMessage("LoginPanel", "OnMobileWxLoginResp", "false;用户取消");
|
||||
break;
|
||||
case -4:
|
||||
UnitySendMessage("LoginPanel", "OnMobileWxLoginResp", "false;用户拒绝授权");
|
||||
break;
|
||||
default:
|
||||
UnitySendMessage("LoginPanel", "OnMobileWxLoginResp", "false;登录失败");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void)onReq:(BaseReq *)req
|
||||
{
|
||||
// do something
|
||||
}
|
||||
|
||||
@end
|
||||
33
Assets/Plugins/iOS/IOSWechatController.m.meta
Normal file
33
Assets/Plugins/iOS/IOSWechatController.m.meta
Normal file
@ -0,0 +1,33 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0cbd70da63d86a34ab0eca9767c1289b
|
||||
PluginImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
iconMap: {}
|
||||
executionOrder: {}
|
||||
defineConstraints: []
|
||||
isPreloaded: 0
|
||||
isOverridable: 0
|
||||
isExplicitlyReferenced: 0
|
||||
validateReferences: 1
|
||||
platformData:
|
||||
- first:
|
||||
Any:
|
||||
second:
|
||||
enabled: 0
|
||||
settings: {}
|
||||
- first:
|
||||
Editor: Editor
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
DefaultValueInitialized: true
|
||||
- first:
|
||||
iPhone: iOS
|
||||
second:
|
||||
enabled: 1
|
||||
settings:
|
||||
AddToEmbeddedBinaries: false
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
205
Assets/Plugins/iOS/WXApi.h
Normal file
205
Assets/Plugins/iOS/WXApi.h
Normal file
@ -0,0 +1,205 @@
|
||||
//
|
||||
// WXApi.h
|
||||
// 所有Api接口
|
||||
//
|
||||
// Created by Wechat on 12-2-28.
|
||||
// Copyright (c) 2012年 Tencent. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "WXApiObject.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
#pragma mark - WXApiDelegate
|
||||
/*! @brief 接收并处理来自微信终端程序的事件消息
|
||||
*
|
||||
* 接收并处理来自微信终端程序的事件消息,期间微信界面会切换到第三方应用程序。
|
||||
* WXApiDelegate 会在handleOpenURL:delegate:中使用并触发。
|
||||
*/
|
||||
@protocol WXApiDelegate <NSObject>
|
||||
@optional
|
||||
|
||||
/*! @brief 收到一个来自微信的请求,第三方应用程序处理完后调用sendResp向微信发送结果
|
||||
*
|
||||
* 收到一个来自微信的请求,异步处理完成后必须调用sendResp发送处理结果给微信。
|
||||
* 可能收到的请求有GetMessageFromWXReq、ShowMessageFromWXReq等。
|
||||
* @param req 具体请求内容,是自动释放的
|
||||
*/
|
||||
- (void)onReq:(BaseReq*)req;
|
||||
|
||||
|
||||
|
||||
/*! @brief 发送一个sendReq后,收到微信的回应
|
||||
*
|
||||
* 收到一个来自微信的处理结果。调用一次sendReq后会收到onResp。
|
||||
* 可能收到的处理结果有SendMessageToWXResp、SendAuthResp等。
|
||||
* @param resp具体的回应内容,是自动释放的
|
||||
*/
|
||||
- (void)onResp:(BaseResp*)resp;
|
||||
|
||||
@end
|
||||
|
||||
#pragma mark - WXApiLogDelegate
|
||||
|
||||
@protocol WXApiLogDelegate <NSObject>
|
||||
|
||||
- (void)onLog:(NSString*)log logLevel:(WXLogLevel)level;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
#pragma mark - WXApi
|
||||
|
||||
/*! @brief 微信Api接口函数类
|
||||
*
|
||||
* 该类封装了微信终端SDK的所有接口
|
||||
*/
|
||||
@interface WXApi : NSObject
|
||||
|
||||
/*! @brief WXApi的成员函数,向微信终端程序注册第三方应用。
|
||||
*
|
||||
* 需要在每次启动第三方应用程序时调用。
|
||||
* @attention 请保证在主线程中调用此函数
|
||||
* @param appid 微信开发者ID
|
||||
* @param universalLink 微信开发者Universal Link
|
||||
* @return 成功返回YES,失败返回NO。
|
||||
*/
|
||||
+ (BOOL)registerApp:(NSString *)appid universalLink:(NSString *)universalLink;
|
||||
|
||||
|
||||
/*! @brief 处理旧版微信通过URL启动App时传递的数据
|
||||
*
|
||||
* 需要在 application:openURL:sourceApplication:annotation:或者application:handleOpenURL中调用。
|
||||
* @param url 微信启动第三方应用时传递过来的URL
|
||||
* @param delegate WXApiDelegate对象,用来接收微信触发的消息。
|
||||
* @return 成功返回YES,失败返回NO。
|
||||
*/
|
||||
+ (BOOL)handleOpenURL:(NSURL *)url delegate:(nullable id<WXApiDelegate>)delegate;
|
||||
|
||||
|
||||
/*! @brief 处理微信通过Universal Link启动App时传递的数据
|
||||
*
|
||||
* 需要在 application:continueUserActivity:restorationHandler:中调用。
|
||||
* @param userActivity 微信启动第三方应用时系统API传递过来的userActivity
|
||||
* @param delegate WXApiDelegate对象,用来接收微信触发的消息。
|
||||
* @return 成功返回YES,失败返回NO。
|
||||
*/
|
||||
+ (BOOL)handleOpenUniversalLink:(NSUserActivity *)userActivity delegate:(nullable id<WXApiDelegate>)delegate;
|
||||
|
||||
|
||||
/*! @brief 检查微信是否已被用户安装
|
||||
*
|
||||
* @return 微信已安装返回YES,未安装返回NO。
|
||||
*/
|
||||
+ (BOOL)isWXAppInstalled;
|
||||
|
||||
|
||||
|
||||
/*! @brief 判断当前微信的版本是否支持OpenApi
|
||||
*
|
||||
* @return 支持返回YES,不支持返回NO。
|
||||
*/
|
||||
+ (BOOL)isWXAppSupportApi;
|
||||
|
||||
|
||||
/*! @brief 判断当前微信的版本是否支持分享微信状态功能
|
||||
*
|
||||
* @attention 需在工程LSApplicationQueriesSchemes配置中添加weixinStateAPI
|
||||
* @return 支持返回YES,不支持返回NO。
|
||||
*/
|
||||
+ (BOOL)isWXAppSupportStateAPI;
|
||||
|
||||
|
||||
/*! @brief 获取微信的itunes安装地址
|
||||
*
|
||||
* @return 微信的安装地址字符串。
|
||||
*/
|
||||
+ (NSString *)getWXAppInstallUrl;
|
||||
|
||||
|
||||
|
||||
/*! @brief 获取当前微信SDK的版本号
|
||||
*
|
||||
* @return 返回当前微信SDK的版本号
|
||||
*/
|
||||
+ (NSString *)getApiVersion;
|
||||
|
||||
|
||||
|
||||
/*! @brief 打开微信
|
||||
*
|
||||
* @return 成功返回YES,失败返回NO。
|
||||
*/
|
||||
+ (BOOL)openWXApp;
|
||||
|
||||
|
||||
|
||||
/*! @brief 发送请求到微信,等待微信返回onResp
|
||||
*
|
||||
* 函数调用后,会切换到微信的界面。第三方应用程序等待微信返回onResp。微信在异步处理完成后一定会调用onResp。支持以下类型
|
||||
* SendAuthReq、SendMessageToWXReq、PayReq等。
|
||||
* @param req 具体的发送请求。
|
||||
* @param completion 调用结果回调block
|
||||
*/
|
||||
+ (void)sendReq:(BaseReq *)req completion:(void (^ __nullable)(BOOL success))completion;
|
||||
|
||||
/*! @brief 收到微信onReq的请求,发送对应的应答给微信,并切换到微信界面
|
||||
*
|
||||
* 函数调用后,会切换到微信的界面。第三方应用程序收到微信onReq的请求,异步处理该请求,完成后必须调用该函数。可能发送的相应有
|
||||
* GetMessageFromWXResp、ShowMessageFromWXResp等。
|
||||
* @param resp 具体的应答内容
|
||||
* @param completion 调用结果回调block
|
||||
*/
|
||||
+ (void)sendResp:(BaseResp*)resp completion:(void (^ __nullable)(BOOL success))completion;
|
||||
|
||||
|
||||
/*! @brief 发送Auth请求到微信,支持用户没安装微信,等待微信返回onResp
|
||||
*
|
||||
* 函数调用后,会切换到微信的界面。第三方应用程序等待微信返回onResp。微信在异步处理完成后一定会调用onResp。支持SendAuthReq类型。
|
||||
* @param req 具体的发送请求。
|
||||
* @param viewController 当前界面对象。
|
||||
* @param delegate WXApiDelegate对象,用来接收微信触发的消息。
|
||||
* @param completion 调用结果回调block
|
||||
*/
|
||||
+ (void)sendAuthReq:(SendAuthReq *)req viewController:(UIViewController*)viewController delegate:(nullable id<WXApiDelegate>)delegate completion:(void (^ __nullable)(BOOL success))completion;
|
||||
|
||||
|
||||
/*! @brief 测试函数,用于排查当前App通过Universal Link方式分享到微信的流程
|
||||
注意1: 调用自检函数之前必须要先调用registerApp:universalLink接口, 并确认调用成功
|
||||
注意2: 自检过程中会有Log产生,可以先调用startLogByLevel函数,根据Log排查问题
|
||||
注意3: 会多次回调block
|
||||
注意4: 仅用于新接入SDK时调试使用,请勿在正式环境的调用
|
||||
*
|
||||
* 当completion回调的step为WXULCheckStepFinal时,表示检测通过,Universal Link接入成功
|
||||
* @param completion 回调Block
|
||||
*/
|
||||
+ (void)checkUniversalLinkReady:(nonnull WXCheckULCompletion)completion;
|
||||
|
||||
|
||||
/*! @brief WXApi的成员函数,接受微信的log信息。byBlock
|
||||
注意1:SDK会强引用这个block,注意不要导致内存泄漏,注意不要导致内存泄漏
|
||||
注意2:调用过一次startLog by block之后,如果再调用一次任意方式的startLoad,会释放上一次logBlock,不再回调上一个logBlock
|
||||
*
|
||||
* @param level 打印log的级别
|
||||
* @param logBlock 打印log的回调block
|
||||
*/
|
||||
|
||||
+ (void)startLogByLevel:(WXLogLevel)level logBlock:(WXLogBolock)logBlock;
|
||||
|
||||
/*! @brief WXApi的成员函数,接受微信的log信息。byDelegate
|
||||
注意1:sdk会弱引用这个delegate,这里可加任意对象为代理,不需要与WXApiDelegate同一个对象
|
||||
注意2:调用过一次startLog by delegate之后,再调用一次任意方式的startLoad,不会再回调上一个logDelegate对象
|
||||
* @param level 打印log的级别
|
||||
* @param logDelegate 打印log的回调代理,
|
||||
*/
|
||||
+ (void)startLogByLevel:(WXLogLevel)level logDelegate:(id<WXApiLogDelegate>)logDelegate;
|
||||
|
||||
/*! @brief 停止打印log,会清理block或者delegate为空,释放block
|
||||
* @param
|
||||
*/
|
||||
+ (void)stopLog;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
33
Assets/Plugins/iOS/WXApi.h.meta
Normal file
33
Assets/Plugins/iOS/WXApi.h.meta
Normal file
@ -0,0 +1,33 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2ab0aef16a26f5644b74f28801dcf547
|
||||
PluginImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
iconMap: {}
|
||||
executionOrder: {}
|
||||
defineConstraints: []
|
||||
isPreloaded: 0
|
||||
isOverridable: 0
|
||||
isExplicitlyReferenced: 0
|
||||
validateReferences: 1
|
||||
platformData:
|
||||
- first:
|
||||
Any:
|
||||
second:
|
||||
enabled: 0
|
||||
settings: {}
|
||||
- first:
|
||||
Editor: Editor
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
DefaultValueInitialized: true
|
||||
- first:
|
||||
iPhone: iOS
|
||||
second:
|
||||
enabled: 1
|
||||
settings:
|
||||
AddToEmbeddedBinaries: false
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
1247
Assets/Plugins/iOS/WXApiObject.h
Normal file
1247
Assets/Plugins/iOS/WXApiObject.h
Normal file
File diff suppressed because it is too large
Load Diff
33
Assets/Plugins/iOS/WXApiObject.h.meta
Normal file
33
Assets/Plugins/iOS/WXApiObject.h.meta
Normal file
@ -0,0 +1,33 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6e517efafdbb3fd47aa83f1733cf045e
|
||||
PluginImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
iconMap: {}
|
||||
executionOrder: {}
|
||||
defineConstraints: []
|
||||
isPreloaded: 0
|
||||
isOverridable: 0
|
||||
isExplicitlyReferenced: 0
|
||||
validateReferences: 1
|
||||
platformData:
|
||||
- first:
|
||||
Any:
|
||||
second:
|
||||
enabled: 0
|
||||
settings: {}
|
||||
- first:
|
||||
Editor: Editor
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
DefaultValueInitialized: true
|
||||
- first:
|
||||
iPhone: iOS
|
||||
second:
|
||||
enabled: 1
|
||||
settings:
|
||||
AddToEmbeddedBinaries: false
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
68
Assets/Plugins/iOS/WechatAuthSDK.h
Normal file
68
Assets/Plugins/iOS/WechatAuthSDK.h
Normal file
@ -0,0 +1,68 @@
|
||||
//
|
||||
// WechatAuthSDK.h
|
||||
// WechatAuthSDK
|
||||
//
|
||||
// Created by 李凯 on 13-11-29.
|
||||
// Copyright (c) 2013年 Tencent. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
enum AuthErrCode {
|
||||
WechatAuth_Err_Ok = 0, //Auth成功
|
||||
WechatAuth_Err_NormalErr = -1, //普通错误
|
||||
WechatAuth_Err_NetworkErr = -2, //网络错误
|
||||
WechatAuth_Err_GetQrcodeFailed = -3, //获取二维码失败
|
||||
WechatAuth_Err_Cancel = -4, //用户取消授权
|
||||
WechatAuth_Err_Timeout = -5, //超时
|
||||
};
|
||||
|
||||
@protocol WechatAuthAPIDelegate<NSObject>
|
||||
@optional
|
||||
|
||||
- (void)onAuthGotQrcode:(UIImage *)image; //得到二维码
|
||||
- (void)onQrcodeScanned; //二维码被扫描
|
||||
- (void)onAuthFinish:(int)errCode AuthCode:(nullable NSString *)authCode; //成功登录
|
||||
|
||||
@end
|
||||
|
||||
@interface WechatAuthSDK : NSObject{
|
||||
NSString *_sdkVersion;
|
||||
__weak id<WechatAuthAPIDelegate> _delegate;
|
||||
}
|
||||
|
||||
@property(nonatomic, weak, nullable) id<WechatAuthAPIDelegate> delegate;
|
||||
@property(nonatomic, readonly) NSString *sdkVersion; //authSDK版本号
|
||||
|
||||
/*! @brief 发送登录请求,等待WechatAuthAPIDelegate回调
|
||||
*
|
||||
* @param appId 微信开发者ID
|
||||
* @param nonceStr 一个随机的尽量不重复的字符串,用来使得每次的signature不同
|
||||
* @param timeStamp 时间戳
|
||||
* @param scope 应用授权作用域,拥有多个作用域用逗号(,)分隔
|
||||
* @param signature 签名
|
||||
* @param schemeData 会在扫码后拼在scheme后
|
||||
* @return 成功返回YES,失败返回NO
|
||||
注:该实现只保证同时只有一个Auth在运行,Auth未完成或未Stop再次调用Auth接口时会返回NO。
|
||||
*/
|
||||
|
||||
- (BOOL)Auth:(NSString *)appId
|
||||
nonceStr:(NSString *)nonceStr
|
||||
timeStamp:(NSString *)timeStamp
|
||||
scope:(NSString *)scope
|
||||
signature:(NSString *)signature
|
||||
schemeData:(nullable NSString *)schemeData;
|
||||
|
||||
|
||||
/*! @brief 暂停登录请求
|
||||
*
|
||||
* @return 成功返回YES,失败返回NO。
|
||||
*/
|
||||
- (BOOL)StopAuth;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
33
Assets/Plugins/iOS/WechatAuthSDK.h.meta
Normal file
33
Assets/Plugins/iOS/WechatAuthSDK.h.meta
Normal file
@ -0,0 +1,33 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5af5dbc4f818a804ebbedc9a933cd573
|
||||
PluginImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
iconMap: {}
|
||||
executionOrder: {}
|
||||
defineConstraints: []
|
||||
isPreloaded: 0
|
||||
isOverridable: 0
|
||||
isExplicitlyReferenced: 0
|
||||
validateReferences: 1
|
||||
platformData:
|
||||
- first:
|
||||
Any:
|
||||
second:
|
||||
enabled: 0
|
||||
settings: {}
|
||||
- first:
|
||||
Editor: Editor
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
DefaultValueInitialized: true
|
||||
- first:
|
||||
iPhone: iOS
|
||||
second:
|
||||
enabled: 1
|
||||
settings:
|
||||
AddToEmbeddedBinaries: false
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
89
Assets/Plugins/iOS/WechatNativeBridge.m
Normal file
89
Assets/Plugins/iOS/WechatNativeBridge.m
Normal file
@ -0,0 +1,89 @@
|
||||
//
|
||||
// NativeBridge.m
|
||||
// Unity-iPhone
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "WXApi.h"
|
||||
|
||||
//这是向微信终端注册你的appid
|
||||
void RegisterApp(const char* appid)
|
||||
{
|
||||
NSString *weichatId = [NSString stringWithFormat:@"%s", appid];
|
||||
|
||||
BOOL installed = [WXApi isWXAppInstalled];
|
||||
NSLog(@"installed result: %@", installed?@"true":@"false");
|
||||
|
||||
BOOL result = [WXApi registerApp:weichatId universalLink:(@"https://wx.powerfun.com.cn/pf2/")];
|
||||
|
||||
NSLog(@"result: %@", result?@"true":@"false");
|
||||
}
|
||||
|
||||
// 调起小程序
|
||||
void LaunchMiniProgram(const char* miniProgramID, const char* path){
|
||||
WXLaunchMiniProgramReq *launchMiniProgramReq = [WXLaunchMiniProgramReq object];
|
||||
launchMiniProgramReq.userName = [NSString stringWithUTF8String:miniProgramID]; //拉起的小程序的username
|
||||
launchMiniProgramReq.path = [NSString stringWithUTF8String:path]; ////拉起小程序页面的可带参路径,不填默认拉起小程序首页,对于小游戏,可以只传入 query 部分,来实现传参效果,如:传入 "?foo=bar"。
|
||||
launchMiniProgramReq.miniProgramType = WXMiniProgramTypeRelease; //拉起小程序的类型
|
||||
[WXApi sendReq:launchMiniProgramReq completion:^(BOOL success) {}];
|
||||
}
|
||||
|
||||
// 分享图片至微信
|
||||
void ShareImgToWX(int scene, UInt8 *msgByteArrayData, int arrayLength, const char* title, const char* description){
|
||||
WXImageObject *imageObject = [WXImageObject object];
|
||||
imageObject.imageData = [[NSData alloc] initWithBytes:msgByteArrayData length:arrayLength];
|
||||
WXMediaMessage *message = [WXMediaMessage message];
|
||||
message.title = [NSString stringWithUTF8String:title];
|
||||
message.description = [NSString stringWithUTF8String:description];
|
||||
// 用APP的Icon做缩略图
|
||||
NSDictionary *infoPlist = [[NSBundle mainBundle] infoDictionary];
|
||||
NSString *icon = [[infoPlist valueForKeyPath:@"CFBundleIcons.CFBundlePrimaryIcon.CFBundleIconFiles"] lastObject];
|
||||
[message setThumbImage:[UIImage imageNamed:icon]];
|
||||
message.mediaObject = imageObject;
|
||||
SendMessageToWXReq *req = [[SendMessageToWXReq alloc] init];
|
||||
req.bText = NO;
|
||||
req.message = message;
|
||||
req.scene = scene;
|
||||
[WXApi sendReq:req completion:nil];
|
||||
}
|
||||
|
||||
// 分享链接至微信
|
||||
void ShareUrlToWX(int scene, const char* url, const char* title, const char* description){
|
||||
WXWebpageObject *webpageObject = [WXWebpageObject object];
|
||||
webpageObject.webpageUrl = [NSString stringWithUTF8String:url];
|
||||
WXMediaMessage *message = [WXMediaMessage message];
|
||||
message.title = [NSString stringWithUTF8String:title];
|
||||
message.description = [NSString stringWithUTF8String:description];
|
||||
// 用APP的Icon做缩略图
|
||||
NSDictionary *infoPlist = [[NSBundle mainBundle] infoDictionary];
|
||||
NSString *icon = [[infoPlist valueForKeyPath:@"CFBundleIcons.CFBundlePrimaryIcon.CFBundleIconFiles"] lastObject];
|
||||
[message setThumbImage:[UIImage imageNamed:icon]];
|
||||
message.mediaObject = webpageObject;
|
||||
SendMessageToWXReq *req = [[SendMessageToWXReq alloc] init];
|
||||
req.bText = NO;
|
||||
req.message = message;
|
||||
req.scene = scene;
|
||||
[WXApi sendReq:req completion:nil];
|
||||
}
|
||||
|
||||
|
||||
//判断是否安装微信
|
||||
bool IsWechatInstalled_iOS()
|
||||
{
|
||||
return [WXApi isWXAppInstalled];
|
||||
}
|
||||
|
||||
//微信登录
|
||||
void WechatLogin(const char* scope,const char* state)
|
||||
{
|
||||
//登录
|
||||
SendAuthReq* req = [[SendAuthReq alloc] init];
|
||||
req.scope = [NSString stringWithUTF8String:scope];
|
||||
req.state = [NSString stringWithUTF8String:state];
|
||||
[WXApi sendReq:req completion:nil];
|
||||
}
|
||||
//打开微信(注意:需要先注册appid)
|
||||
void OpenWXApp()
|
||||
{
|
||||
[WXApi openWXApp];
|
||||
}
|
||||
33
Assets/Plugins/iOS/WechatNativeBridge.m.meta
Normal file
33
Assets/Plugins/iOS/WechatNativeBridge.m.meta
Normal file
@ -0,0 +1,33 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9ba744e6ebf3c3048baab0a17ad58af0
|
||||
PluginImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
iconMap: {}
|
||||
executionOrder: {}
|
||||
defineConstraints: []
|
||||
isPreloaded: 0
|
||||
isOverridable: 0
|
||||
isExplicitlyReferenced: 0
|
||||
validateReferences: 1
|
||||
platformData:
|
||||
- first:
|
||||
Any:
|
||||
second:
|
||||
enabled: 0
|
||||
settings: {}
|
||||
- first:
|
||||
Editor: Editor
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
DefaultValueInitialized: true
|
||||
- first:
|
||||
iPhone: iOS
|
||||
second:
|
||||
enabled: 1
|
||||
settings:
|
||||
AddToEmbeddedBinaries: false
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
BIN
Assets/Plugins/iOS/libWeChatSDK.a
Normal file
BIN
Assets/Plugins/iOS/libWeChatSDK.a
Normal file
Binary file not shown.
80
Assets/Plugins/iOS/libWeChatSDK.a.meta
Normal file
80
Assets/Plugins/iOS/libWeChatSDK.a.meta
Normal file
@ -0,0 +1,80 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5fd23b9d6d5286d4fba4c1e792198a28
|
||||
PluginImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
iconMap: {}
|
||||
executionOrder: {}
|
||||
defineConstraints: []
|
||||
isPreloaded: 0
|
||||
isOverridable: 0
|
||||
isExplicitlyReferenced: 0
|
||||
validateReferences: 1
|
||||
platformData:
|
||||
- first:
|
||||
: Any
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
Exclude Android: 1
|
||||
Exclude Editor: 1
|
||||
Exclude Linux64: 1
|
||||
Exclude OSXUniversal: 1
|
||||
Exclude Win: 1
|
||||
Exclude Win64: 1
|
||||
Exclude iOS: 0
|
||||
- first:
|
||||
Android: Android
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: ARMv7
|
||||
- first:
|
||||
Any:
|
||||
second:
|
||||
enabled: 0
|
||||
settings: {}
|
||||
- first:
|
||||
Editor: Editor
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: AnyCPU
|
||||
DefaultValueInitialized: true
|
||||
OS: AnyOS
|
||||
- first:
|
||||
Standalone: Linux64
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: x86_64
|
||||
- first:
|
||||
Standalone: OSXUniversal
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: x86_64
|
||||
- first:
|
||||
Standalone: Win
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: x86
|
||||
- first:
|
||||
Standalone: Win64
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: x86_64
|
||||
- first:
|
||||
iPhone: iOS
|
||||
second:
|
||||
enabled: 1
|
||||
settings:
|
||||
AddToEmbeddedBinaries: false
|
||||
CPU: AnyCPU
|
||||
CompileFlags:
|
||||
FrameworkDependencies: Security;WebKit;
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/Resources/Mobile.meta
Normal file
8
Assets/Resources/Mobile.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f134d222725933a4a8aa79fee0ebc10c
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
14882
Assets/Scenes/Login-Mobile.unity
Normal file
14882
Assets/Scenes/Login-Mobile.unity
Normal file
File diff suppressed because it is too large
Load Diff
7
Assets/Scenes/Login-Mobile.unity.meta
Normal file
7
Assets/Scenes/Login-Mobile.unity.meta
Normal file
@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4be878da00cf764499988cf403faf94d
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -68,7 +68,7 @@ public static class App
|
||||
}
|
||||
|
||||
public static string CurrentScene { get; set; }//当前场景
|
||||
|
||||
public static WeChatController weChatController = new WeChatController();
|
||||
static App()
|
||||
{
|
||||
#if !UNITY_EDITOR
|
||||
|
||||
8
Assets/Scripts/Mobile.meta
Normal file
8
Assets/Scripts/Mobile.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f2c27d8ea9a20894180ddf2895a82fed
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
35
Assets/Scripts/Mobile/LoginControllerMobile.cs
Normal file
35
Assets/Scripts/Mobile/LoginControllerMobile.cs
Normal file
@ -0,0 +1,35 @@
|
||||
using Assets.Scripts;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class LoginControllerMobile : MonoBehaviour
|
||||
{
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
private void ShowThirdLoginPage()
|
||||
{
|
||||
|
||||
}
|
||||
private void HideThirdLoginPage()
|
||||
{
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// 从ios或者安卓接收code,在c#里不建议调用
|
||||
/// </summary>
|
||||
/// <param name="res"></param>
|
||||
public void OnMobileWxLoginResp(string res)
|
||||
{
|
||||
Utils.showToast(gameObject, res, type: 1);
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Mobile/LoginControllerMobile.cs.meta
Normal file
11
Assets/Scripts/Mobile/LoginControllerMobile.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d8bafb22521430b43985508b40e72fd4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
174
Assets/Scripts/Mobile/WeChatController.cs
Normal file
174
Assets/Scripts/Mobile/WeChatController.cs
Normal file
@ -0,0 +1,174 @@
|
||||
using System.Runtime.InteropServices;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// Create By Jooki: https://www.yuque.com/jooki
|
||||
/// 使用流程:
|
||||
/// WeChatController是一个单例, 请自行给变量 _className 赋值
|
||||
/// 使用前先调用 Init() 进行初始化,然后调用 IsWeChatAppInstalled() 检查用户设备上是否安装了微信;
|
||||
/// 之后为保险起见调用 IsWeChatAppInstalled() 判断微信是否已经安装;
|
||||
/// 最后就是按照需要分享的消息类型调用对应的方法
|
||||
/// </summary>
|
||||
public class WeChatController
|
||||
{
|
||||
|
||||
#region iOS微信SDK
|
||||
#if UNITY_IOS
|
||||
[DllImport("__Internal")]
|
||||
private static extern void RegisterApp(string appid);
|
||||
|
||||
[DllImport("__Internal")]
|
||||
private static extern bool IsWechatInstalled_iOS();
|
||||
|
||||
[DllImport("__Internal")]
|
||||
private static extern void WechatLogin(string scope,string state);
|
||||
#endif
|
||||
#endregion
|
||||
/// <summary>
|
||||
/// com.unityplugins.wechatshare是在Android Studio中创建的 Module,
|
||||
/// MainActivity 是一个Activity, 对外供C#调用的方法都写在这个Activity内
|
||||
/// </summary>
|
||||
private readonly string _className = "com.unityplugins.wechatshare.MainActivity";
|
||||
private string _APP_ID = "";
|
||||
private AndroidJavaClass mainActivityClass = null;
|
||||
|
||||
private static WeChatController _instance;
|
||||
public static WeChatController Instance
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_instance == null)
|
||||
{
|
||||
_instance = new WeChatController();
|
||||
}
|
||||
return _instance;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 初始化微信SDK, APPID是用户在微信开放平台注册是所分配的应用唯一标识, 可在微信开放平台找到
|
||||
/// </summary>
|
||||
/// <param name="APPID"></param>
|
||||
public void Init(string APPID)
|
||||
{
|
||||
_APP_ID = APPID;
|
||||
#if !UNITY_EDITOR && UNITY_ANDROID
|
||||
mainActivityClass = new AndroidJavaClass(_className);
|
||||
// 第一个参数: MainActivity中的方法名
|
||||
// 第二、三个参数: 分别是SendMessageToUnity需要接收的第一和第二个参数,对比上面Java的代码
|
||||
mainActivityClass.CallStatic("InitWeChat", Application.identifier, _APP_ID);
|
||||
#endif
|
||||
#if !UNITY_EDITOR && UNITY_IOS
|
||||
RegisterApp(_APP_ID);
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 判断是否是否安装了微信
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public bool IsWeChatAppInstalled()
|
||||
{
|
||||
#if UNITY_ANDROID
|
||||
return mainActivityClass.CallStatic<bool>("IsWeChatInstalled");
|
||||
#elif UNITY_IOS
|
||||
return IsWechatInstalled_iOS();
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 分享链接至微信,缩略图用的是APP Icon
|
||||
/// </summary>
|
||||
/// <param name="scene">分享至什么场景, 0-对话、1-朋友圈、2-收藏</param>
|
||||
/// <param name="url">网页链接</param>
|
||||
/// <param name="title">标题</param>
|
||||
/// <param name="description">描述</param>
|
||||
public void ShareWebpageToWX(int scene, string url, string title, string description)
|
||||
{
|
||||
mainActivityClass.CallStatic("ShareWebpageToWX", scene, url, title, description);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 分享文字至微信
|
||||
/// </summary>
|
||||
/// <param name="scene">分享至什么场景, 0-对话、1-朋友圈、2-收藏</param>
|
||||
/// <param name="text">要分享的文本内容</param>
|
||||
public void ShareTextToWX(int scene, string text)
|
||||
{
|
||||
mainActivityClass.CallStatic("ShareTextToWX", scene, text);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 分享图片至微信
|
||||
/// </summary>
|
||||
/// <param name="scene">分享至什么场景, 0-对话、1-朋友圈、2-收藏</param>
|
||||
/// <param name="image">要分享的图片</param>
|
||||
public void ShareImageToWX(int scene, Texture2D image)
|
||||
{
|
||||
mainActivityClass.CallStatic("ShareImageToWX", scene, ImageToBytes(image));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 分享音乐至微信
|
||||
/// </summary>
|
||||
/// <param name="scene">分享至什么场景, 0-对话、1-朋友圈、2-收藏</param>
|
||||
/// <param name="musicUrl">音乐的URL</param>
|
||||
/// <param name="title">标题</param>
|
||||
/// <param name="description">描述</param>
|
||||
public void ShareMusicToWX(int scene, string musicUrl, string title, string description)
|
||||
{
|
||||
mainActivityClass.CallStatic("ShareMusicToWX", scene, musicUrl, title, description);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 分享视频至微信
|
||||
/// </summary>
|
||||
/// <param name="scene">分享至什么场景, 0-对话、1-朋友圈、2-收藏</param>
|
||||
/// <param name="videoUrl">视频的URL</param>
|
||||
/// <param name="title">标题</param>
|
||||
/// <param name="description">描述</param>
|
||||
public void ShareVideoToWX(int scene, string videoUrl, string title, string description)
|
||||
{
|
||||
mainActivityClass.CallStatic("ShareVideoToWX", scene, videoUrl, title, description);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 分享小程序至微信
|
||||
/// </summary>
|
||||
/// <param name="scene">分享至什么场景, 0-对话、1-朋友圈、2-收藏</param>
|
||||
/// <param name="lowVersionUrl">兼容低版本的网页链接</param>
|
||||
/// <param name="miniProgramAPPID">小程序原始ID, 获取方法:登录小程序管理后台-设置-基本设置-帐号信息</param>
|
||||
/// <param name="path">小程序页面路径;对于小游戏,可以只传入 query 部分,来实现传参效果,如:传入 "?foo=bar"</param>
|
||||
/// <param name="title">标题</param>
|
||||
/// <param name="description">描述</param>
|
||||
/// <param name="coverImg">分享封面图片</param>
|
||||
public void ShareMinniProgramToWX(int scene, string lowVersionUrl, string miniProgramAPPID, string path,
|
||||
string title, string description, Texture2D coverImg)
|
||||
{
|
||||
mainActivityClass.CallStatic("ShareMinniProgramToWX", scene, lowVersionUrl, miniProgramAPPID, path, title, description, ImageToBytes(coverImg));
|
||||
}
|
||||
public void WxLogin(string scope, string state)
|
||||
{
|
||||
#if UNITY_ANDROID
|
||||
mainActivityClass.CallStatic("WxLogin", scope, state);
|
||||
#elif UNITY_IOS
|
||||
WechatLogin(scope, state);
|
||||
#endif
|
||||
|
||||
}
|
||||
public void SendMessageToUnity(string gameObjectName, string UnityMethodName)
|
||||
{
|
||||
mainActivityClass.CallStatic("SendMessageToUnity",gameObjectName, UnityMethodName);
|
||||
}
|
||||
/// <summary>
|
||||
/// 把一张Texture2D的图片信息转为Byte[]
|
||||
/// </summary>
|
||||
/// <param name="texture"></param>
|
||||
/// <returns></returns>
|
||||
private byte[] ImageToBytes(Texture2D texture)
|
||||
{
|
||||
var imageData = texture.EncodeToPNG();
|
||||
return imageData;
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Mobile/WeChatController.cs.meta
Normal file
11
Assets/Scripts/Mobile/WeChatController.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 94968fb42ad40634ab6b22df87c405cf
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -454,11 +454,28 @@ public class LoginController : MonoBehaviour
|
||||
{ "Days",signForm.days},
|
||||
};
|
||||
avatar = Resources.Load<Texture>("Images/New Account");
|
||||
#if UNITY_ANDROID || UNITY_IOS
|
||||
transform.Find("Version").GetComponent<Text>().text = $"V{App.AppVersion}";
|
||||
#else
|
||||
transform.Find("Panel").Find("Version").GetComponent<Text>().text = $"V{App.AppVersion}";
|
||||
#endif
|
||||
}
|
||||
public void Test(string key)
|
||||
{
|
||||
Debug.Log(key);
|
||||
}
|
||||
|
||||
async void Init()
|
||||
{
|
||||
|
||||
#if !UNITY_EDITOR && (UNITY_ANDROID || UNITY_IOS)
|
||||
var weChat = App.weChatController;
|
||||
//WeChatController weChat = new WeChatController();
|
||||
weChat.Init("wx9146e6697a6aef2d");
|
||||
if (weChat.IsWeChatAppInstalled())
|
||||
{
|
||||
weChat.WxLogin("snsapi_userinfo", "");
|
||||
}
|
||||
#endif
|
||||
UIManager.Instance.ModalsPanel = this.transform.Find("ModalPanel").GetComponent<PFUIPanel>();
|
||||
userInfos = UIManager.Instance.userInfos;
|
||||
App.DefaultRotateTexture = Utils.ReadTextureFromPlayerPrefs("rotateImage");
|
||||
@ -910,10 +927,12 @@ public class LoginController : MonoBehaviour
|
||||
/// </summary>
|
||||
private void goLoginImmediately()
|
||||
{
|
||||
#if !(UNITY_IOS || UNITY_ANDROID)
|
||||
imagedf.localPosition = new Vector3(-580, -34, 0);
|
||||
imagexf.localPosition = new Vector3(0, -669, 0);
|
||||
LoginBg.localPosition = Vector3.zero;
|
||||
LoginBg.GetComponent<RectTransform>().sizeDelta = new Vector2(360, 573);
|
||||
#endif
|
||||
var scrollValue = 1f / (pageNums - 1);
|
||||
var value = 1 * scrollValue;
|
||||
scrollPanel.horizontalNormalizedPosition = value;
|
||||
@ -924,6 +943,7 @@ public class LoginController : MonoBehaviour
|
||||
/// </summary>
|
||||
void ReturnQuick()
|
||||
{
|
||||
#if !(UNITY_IOS || UNITY_ANDROID)
|
||||
if (imagexf != null)
|
||||
{
|
||||
imagexf.DOLocalMoveY(-575, 0.3f);
|
||||
@ -937,6 +957,7 @@ public class LoginController : MonoBehaviour
|
||||
LoginBg.GetComponent<RectTransform>().DOSizeDelta(new Vector2(360, 385), 0.3f);
|
||||
LoginBg.GetComponent<RectTransform>().DOLocalMoveY(-94, 0.3f);
|
||||
}
|
||||
#endif
|
||||
this.StartScrollPanel(0);
|
||||
}
|
||||
/// <summary>
|
||||
@ -945,6 +966,7 @@ public class LoginController : MonoBehaviour
|
||||
/// <param name="noReturn"></param>
|
||||
public void goLogin(bool noReturn = false)
|
||||
{
|
||||
#if !(UNITY_IOS || UNITY_ANDROID)
|
||||
if (imagexf != null)
|
||||
{
|
||||
imagexf.DOLocalMoveY(-669, 0.3f);
|
||||
@ -958,6 +980,7 @@ public class LoginController : MonoBehaviour
|
||||
LoginBg.GetComponent<RectTransform>().DOSizeDelta(new Vector2(360, 573), 0.3f);
|
||||
LoginBg.GetComponent<RectTransform>().DOLocalMoveY(0, 0.3f);
|
||||
}
|
||||
#endif
|
||||
//DOTween.To(() => o, x => o = x, t, 0.3f);
|
||||
this.StartScrollPanel(1);
|
||||
if (noReturn)
|
||||
|
||||
@ -6,8 +6,8 @@ EditorBuildSettings:
|
||||
serializedVersion: 2
|
||||
m_Scenes:
|
||||
- enabled: 1
|
||||
path: Assets/Scenes/Login.unity
|
||||
guid: 6dce3e17997730b4492f91dd8fede429
|
||||
path: Assets/Scenes/Login-Mobile.unity
|
||||
guid: 4be878da00cf764499988cf403faf94d
|
||||
- enabled: 1
|
||||
path: Assets/Scenes/MainScene.unity
|
||||
guid: ab586a3c1bacd4a48a55178eb06fe0cc
|
||||
|
||||
@ -38,7 +38,6 @@ GraphicsSettings:
|
||||
- {fileID: 16000, guid: 0000000000000000f000000000000000, type: 0}
|
||||
- {fileID: 16001, guid: 0000000000000000f000000000000000, type: 0}
|
||||
- {fileID: 17000, guid: 0000000000000000f000000000000000, type: 0}
|
||||
- {fileID: 16003, guid: 0000000000000000f000000000000000, type: 0}
|
||||
m_PreloadedShaders: []
|
||||
m_SpritesDefaultMaterial: {fileID: 10754, guid: 0000000000000000f000000000000000,
|
||||
type: 0}
|
||||
|
||||
@ -177,7 +177,8 @@ PlayerSettings:
|
||||
androidSupportedAspectRatio: 1
|
||||
androidMaxAspectRatio: 2.1
|
||||
applicationIdentifier: {}
|
||||
buildNumber: {}
|
||||
buildNumber:
|
||||
iPhone: 2.0.1.0
|
||||
AndroidBundleVersionCode: 1
|
||||
AndroidMinSdkVersion: 24
|
||||
AndroidTargetSdkVersion: 0
|
||||
@ -257,15 +258,15 @@ PlayerSettings:
|
||||
AndroidTargetArchitectures: 1
|
||||
AndroidSplashScreenScale: 0
|
||||
androidSplashScreen: {fileID: 0}
|
||||
AndroidKeystoreName:
|
||||
AndroidKeyaliasName:
|
||||
AndroidKeystoreName: '{inproject}: Assets/Plugins/Android/powerfun.keystore'
|
||||
AndroidKeyaliasName: powerfun
|
||||
AndroidBuildApkPerCpuArchitecture: 0
|
||||
AndroidTVCompatibility: 0
|
||||
AndroidIsGame: 1
|
||||
AndroidEnableTango: 0
|
||||
androidEnableBanner: 1
|
||||
androidUseLowAccuracyLocation: 0
|
||||
androidUseCustomKeystore: 0
|
||||
androidUseCustomKeystore: 1
|
||||
m_AndroidBanners:
|
||||
- width: 320
|
||||
height: 180
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user