将唯一的电话ID作为电子邮件发送

时间:2012-09-12 11:01:39

标签: windows-phone-7

我尝试创建一个允许用户注册自己服务的应用。 问题在于,我可以将每个用户限制为一个非常简单的帐户 我想通过Phone唯一ID和windows live id可以做到这一点 我也想出了如何在应用程序中获取这些,但现在我的问题是如何让他们给我! 任何人都可以帮助我如何将带有所需用户名的电话ID发送到我的电子邮件地址? 谢谢

修改

我使用此代码获取所需的值

public static class ExtendedPropertyHelper  
{  
    private static readonly int ANIDLength = 32;  
    private static readonly int ANIDOffset = 2;  
    public static string GetManufacturer()  
    {  
        string result = string.Empty;  
        object manufacturer;  
        if (DeviceExtendedProperties.TryGetValue("DeviceManufacturer", out manufacturer))  
            result = manufacturer.ToString();  

        return result;  
    }  

    //Note: to get a result requires ID_CAP_IDENTITY_DEVICE  
    // to be added to the capabilities of the WMAppManifest  
    // this will then warn users in marketplace  
    public static byte[] GetDeviceUniqueID()  
    {  
        byte[] result = null;  
        object uniqueId;  
        if (DeviceExtendedProperties.TryGetValue("DeviceUniqueId", out uniqueId))  
            result = (byte[])uniqueId;  

        return result;  
    }  

    // NOTE: to get a result requires ID_CAP_IDENTITY_USER  
    //  to be added to the capabilities of the WMAppManifest  
    // this will then warn users in marketplace  
    public static string GetWindowsLiveAnonymousID()  
    {  
        string result = string.Empty;  
        object anid;  
        if (UserExtendedProperties.TryGetValue("ANID", out anid))  
        {  
            if (anid != null && anid.ToString().Length >= (ANIDLength + ANIDOffset))  
            {  
                result = anid.ToString().Substring(ANIDOffset, ANIDLength);  
            }  
        }  

        return result;  
    }  
}  

现在我需要将这些存储在变量中(我不能真正开始工作),然后将它们发送到我的php脚本中,然后提取它们

除此之外,我还要求用户输入他的电子邮件地址并将其包含在POST中, 你能帮忙吗?

2 个答案:

答案 0 :(得分:0)

如果“我的服务”是一项Web服务,那么您可以使用Web服务而不是邮件系统。

在任何一种情况下,您都可以使用Convert.ToBase64String(phoneId)将手机ID转换为字符串。

要通过邮件从WP7发送字符串,您需要使用EmailComposeTask。

答案 1 :(得分:0)

您可以从DeviceExtendedProperties.DeviceUniqueId命名空间获取Microsoft.Phone.Info。 不要忘记在WMAppManifest.xml

中声明 像这样:

<Capabilities>
  <Capability Name="ID_CAP_IDENTITY_DEVICE"/>
  <Capability Name="ID_CAP_IDENTITY_USER"/>
</Capabilities>

链接到msdn here

然后,您可以将此ID发送到您的电子邮箱:

var emailComposeTask = new EmailComposeTask
{
    To = "your-email@domiain.com",
    Subject = "Test Message using EmailComposeTask",
    Body = deviceId
};
emailComposeTask.Show();

但是这将打开一个电子邮件客户端,我不认为用户会非常友好地向您发送电子邮件。因此,您最好向服务器发送POST请求

     private void Button_Click(object sender, RoutedEventArgs e)
    {
        //collect all data you need:
        var deviceId = Convert.ToBase64String(ExtendedPropertyHelper.GetDeviceUniqueID());
        var userName = ExtendedPropertyHelper.GetWindowsLiveAnonymousID();
        var manufatcurer = ExtendedPropertyHelper.GetManufacturer();
        //create request string
        //[see the explanation on MSDN][2]
        var requestUrl = string
  .Format("http://myPageUrlAddress.com/script.aspx?deviceid={0}&user={1}&manufacturer={2}",
   deviceId, userName, manufatcurer);


        System.Uri myUri = new System.Uri(requestUrl);
        //create a request instance
        HttpWebRequest myRequest = (HttpWebRequest)HttpWebRequest.Create(myUri);
        myRequest.Method = "POST";
        myRequest.ContentType = "application/x-www-form-urlencoded";
        //and it will be sent. 
        //Also you need to create GetRequestStreamCallback method to 
        //handle server responce.
        myRequest.BeginGetRequestStream(new
        AsyncCallback(GetRequestStreamCallback), myRequest);
    }
    //this method is empty. You can show tha dialog box about successful sending.
    public void GetRequestStreamCallback(IAsyncResult result) { ; }

电子邮件怎么样 - 只需在同一页面上创建一个TextBox,并将用户输入保存到变量中。